I have ArrayList with name and id.
list.add(new Model2(null, "name1"));
list.add(new Model2("13", "name2"));
list.add(new Model2(null, "name1"));
list.add(new Model2("13", "name4"));
list.add(new Model2(null, "name1"));
list.add(new Model2("13", "name6"));
First if id is null and then by the name
//the result should by like this:
//1. null , name1
//2. null , name1
//3. null , name1
//4. 13,name2
//5. 13,name4
//6. 13,name6
I know how to sort the null values:
Collections.sort(list,sorting());
public static Comparator<? super Model2> sorting() {
Comparator<Model2> sortedList = new Comparator<Model2>() {
@Override
public int compare(Model2 o1, Model2 o2) {
return o1.getId() == null ? -1 : 0;
}
};
return sortedList;
}
But what about the names values?