I have e.g list of elemenets like sg-1, sg-5, sg-13, sg-6 and etc and i need sort them by numbers. The part of my code is:
}).map(c -> { System.out.println(c); return c; }).distinct() .sorted((c1, c2) -> c1.substring(c1.indexOf("-"), c1.length()) .compareTo(c2.substring(c2.indexOf("-"), c2.length()))) .collect(Collectors.toList()); system out prints sg-1 sg-1 sg-1 sg-9 sg-1 sg-4 sg-15 sg-1 sg-1 sg-1 sg-1
But in the end I get [sg-1, sg-15, sg-4, sg-9] however it has to be [sg-1, sg-4, sg-9, sg-15] How to sort them, please help my :)