For example's sake, I will say I have 10 Strings in an ArrayList which each represent a person's name and age:
David:43
John:10
Wilson:23
George:59
Pat:3
Tom:52
Sydney:32
Mohammed:72
Jay:34
Adam:18
We'll call this ArrayList "people"
They are all in my ArrayList. I am able to get the age by using
Integer.parseInt(people.get(index).split(":")[1]);
But I want to sort the ArrayList to print out the people from highest to lowest age. I was wondering if there is any way to do this. And if there is, are there more efficient ways to do it?
Collections.sort()with aComparatorthat does the age parsing.