I have an ArrayList version string that I would like to sort so that the first one is the first.
ArrayList<String> items = new ArrayList<String>();
items.add("4.1.0");
items.add("4.1.1");
items.add("4.1");
items.add("5.1");
items.add("4.0.1");
My expected result:
5.1
4.1.1
4.1.0
4.1
4.0.1
When considering values as integers, "4.0.1" is greater than "4.1", which is not true for versions.
I am thinking of using a comparator interface for each major, minor, and incremental version. Is there an easier way to do this?
source
share