How to sort a List of objects by their date (java collections, List<Object>)

前端 未结 6 1397
迷失自我
迷失自我 2020-12-25 15:20
private List movieItems = null;
public List getMovieItems() {
    final int first = 0;
    if (movieItems == null) {
        getPagingInfo(         


        
6条回答
  •  Happy的楠姐
    2020-12-25 15:43

    In your compare method, o1 and o2 are already elements in the movieItems list. So, you should do something like this:

    Collections.sort(movieItems, new Comparator() {
        public int compare(Movie m1, Movie m2) {
            return m1.getDate().compareTo(m2.getDate());
        }
    });
    

提交回复
热议问题