I am trying to sort an ArrayList<String>. The strings in the list look like this "abc 123 def 456" and I want to sort the list such that the string with the smallest last number comes first e.g. if the elements are
{"abc 123 def 456", "ghi 456 jkl 789", "mno 101 pqr 112"}
then I want the sorted list to have the third String first, then the first String, and then the second String.
{"mno 101 pqr 112", "abc 123 def 456","ghi 456 jkl 789"}
Just like this.
I tried to sort it using list.split(" "), Double.parseDouble(String)and Collections.sort(list), but I don't now how I could connect the remainder of my Strings correctly with the list of sorted numbers.
Edit:
String[] numbers = list.get(i).split(" ");
numberList.add(Integer.parseInt(numbers[3]));
Collections.sort(numberList);
Now I know how the numbers should be sorted, but I can't reconnect them with the rest of "their String".