I have a list of objects ordered by a date parameter and want to reorder them by category parameter, but keeping the date order within the category.
Is something like this enough, or do I have to implement a comparator that takes on account the date for objects of the same category?
// sort the list by category asc(, date asc )
Collections.sort((List<Object>)entries, new Comparator<Object>() {
@Override public int compare(Object elementA, Object elementB) {
return elementA.category.compareTo(elementB.category); // what happens when elementA.category.equals(elementB.category)?
}
});
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…