I need to sort a Set of String\'s which holds number.Ex: [15, 13, 14, 11, 12, 3, 2, 1, 10, 7, 6, 5, 4, 9, 8]. I need to sort it to [1, 2, 3, 4, 5, 6, 7, 8, 9,
Ex: [15, 13, 14, 11, 12, 3, 2, 1, 10, 7, 6, 5, 4, 9, 8]
[1, 2, 3, 4, 5, 6, 7, 8, 9,
Your Strings will be sorted as Strings in natural order, and not as numbers. So, "11" comes after "10" and "2" will come after "11111111110".
"11"
"10"
"2"
"11111111110"
What to do?.
Use Integer.parseInt() to parse each String value in the set as integer, then add them to a set and call Collections.sort().
Integer.parseInt()
Collections.sort()