How to sort an ArrayList in Java
by ventrix on Sep.22, 2009, under android, java
Example:
Class Test {
public String name;
public String sirName;
}
ArrayList<Test> res = new ArrayList<Test>();
res.add(…);
res.add(…);
Comparator<Test> comperator = new Comparator<Test>() {
@Override
public int compare(Test object1, Test object2) {
return object1.name.compareToIgnoreCase(object2.name);
}
};
Collections.sort(res, comperator);
the list is now sorted by name.
![]()
1 comment for this entry:
April 3rd, 2010 on 3:43 am
a BIG BIG BIG thanks from germany