Sort ArrayList <String> by number
I have an ArrayList video solution that looks like this:
"1024x768", "800x600", "1280x1024", etc.
I want to sort it based on the numeric value in the first part of the string. Those. the above would look like this:
"800x600", "1024x768", "1280x1024"
Is there a quick and dirty way to do this, I mean less than 2-3 lines of code? If not, what will be the right way? The values that I receive refer to an object that does not belong to me. It has getWidth () and getHeight () methods that return ints.
The solution proposed by Shadwell in his answer is correct and idiomatic.
But if you are looking for a more concise solution, I would advise you to use lambdaj , which will allow you to write code like:
List<Resolution> sortedResolutions = sort(resolutions, on(Resolution.class).getWidth());