对象的 ArrayList 的降序排序

Descending Sorting of an ArrayList of Object

我需要对这个 ArrayObject 进行排序:

public ArrayList<WPPost> posts;

下降:

posts.get(i).getRating()

我已经尝试使用 HashMaps、LinkedHashMaps,但我没有找到任何东西。什么是最好的解决方案?

我认为最好的解决方案之一是使用 Collections.sort

    Collections.sort(posts, new Comparator<WPPost>() {
        @Override
        public int compare(WPPost o1, WPPost o2) {
            return o2.getRating() - o1.getRating();
        }
    });

在某些实现中,Collectios 排序使用 合并排序 算法,这会给您带来 O(log n) 的复杂度。