I have ArrayList<Item> itemList. The Class Item contains two fields: char firstLetter and char secondLetter.
If I wanted to sort itemList on firstLetter, the code would be
Collections.sort(itemList, new Comparator<Item>() {
@Override
public int compare(Item o1, Item o2) {
char order1 = o1.getFirstLetter();
char order2 = o2.getFirstLetter();
return Character.compare(order1,order2);
}
});
However, within the same sorting operation I want itemList also to be sorted according to secondLetter. So items that have the same value for firstLetter are sorted among them according to their value for secondLetter. How should the above code be modified?