Sorting set of string numbers in java -
i need sort set of string's holds number.ex: [15, 13, 14, 11, 12, 3, 2, 1, 10, 7, 6, 5, 4, 9, 8]
. need sort [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
. when use collections.sort(keylist);
keylist set, reult obtained [1, 10, 11, 12, 13, 14, 15, 2, 3, 4, 5, 6, 7, 8, 9]
. please help.
write custom comparator , parse argument collections.sort(collection,comparator)
. 1 solution parsing strings integers.
collections.sort(keylist, new comparator<string>() { @override public int compare(string s1, string s2) { integer val1 = integer.parseint(s1); integer val2 = integer.parseint(s2); return val1.compareto(val2); } });
Comments
Post a Comment