Hello there i need to sort my array list that contains the following kind of data:
name1 1111 1622 122ks
name3 1211 4122 1aks
name2 1113 1322 12sks
name10 2111 1222 12dks
...
name4 asd1 2334 asd8
There is simple Model class to populate date! Now What i Want to do is to compare on the bases of the name i.e name1 compare to name2 and so on. For this I am doing like:
public class ABC implements Comparator<MyModel> {
@Override
public int compare(MyModel o1, MyModel o2) {
return o1.name.compareTo(o2.name);
}
}
It give me the output as I required! But when there are name more than 10 i Mean names after 10 11 12 my comparator wont gives me the required sorted list as i need, and the output becomes:
name1 1111 1622 122ks
name10 1211 4122 1aks
name11 1113 1322 12sks
name12 2111 1222 12dks
...
name2 asd1 2334 asd8
... (sorted so on)
What i been doing wrong? Is the way I am doing is wrong or there is some other way to achieve it! Thanks in advance!