String s = "vttqexwqgdc";
char[] ch = s.toCharArray();
int[] indices = {9, 5, 8, 0, 4, 3, 6, 10, 1, 2, 7};
ArrayList<String> list = new ArrayList<>();
for (int i = 0, j = 0; i < ch.length; i++, j++) {
list.add((indices[j] + "" + ch[i]));
}
Collections.sort(list);
System.out.println(list); // **[0q, 10q, 1g, 2d, 3x, 4e, 5t, 6w, 7c, 8t, 9v], Here the 10q should be after 9
**String str = "";
for (String value : list) {
str = str + value;
}
str = str.replaceAll("\\d", "");
System.out.println(str);
please help me how can i sort it, where i can place 10q after 9v.
Thank you Everyone
sorting the answer ,
This works
list.sort((a, b) -> Integer.parseInt(a.replaceAll("[a-zA-Z]", "")) - Integer.parseInt(b.replaceAll("[a-zA-z]", "")));
This is the same has the above but with the Comparator
list.sort(Comparator.comparingInt(a -> Integer.parseInt(a.replaceAll("[a-zA-Z]", ""))));