Prior to Java 8:
noteLst.sort(new Comparator<Notes>() {
@Override
public int compare(Notes n1, Notes n2) {
return n1.getId()-n2.getId();
}
});
In Java 8:
public class TestNotes {
public static void main(String[] args) {
List<Notes> noteLst = new ArrayList<>();
noteLst.add(new Notes(1, "aa", 11));
noteLst.add(new Notes(3, "cc", 33));
noteLst.add(new Notes(4, "bb", 44));
noteLst.add(new Notes(2, "dd", 34));
noteLst.add(new Notes(5, "zz", 32));
noteLst.sort((n1, n2)->n1.getId()-n2.getId());
noteLst.forEach((note)->System.out.println(note));
}
}
Notes [id=1, tagName=aa, tagId=11]
Notes [id=2, tagName=dd, tagId=34]
Notes [id=3, tagName=cc, tagId=33]
Notes [id=4, tagName=bb, tagId=44]
Notes [id=5, tagName=zz, tagId=32]