I am using the following java code to sort the values: –
Collections.sort(values);
It is working correctly except that it is sorting as follows: –
1 10 2 3 4
I need it to sort as follows: –
1 2 3 4 10
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You are sorting
Strings. You can change values to store a subclass ofNumberor implement your ownComparatorto pass as the segment argument of thesortmethod which will do a “natural sort.”See this question for more details: Natural sort order string comparison in Java – is one built in?