Skip to content

Collections

About 162 wordsLess than 1 minute

2025-05-06

一、Collections方法源代码

public static <T extends Comparable<? super T>> void sort(List<T> list)

排序方法,底层使用的是列表的排序方法,可以传入一个Comparator的参数。

相同方法:

public static <T> void sort(List<T> list, Comparator<? super T> c)

public static <T extends Comparable<? super T>> void sort(List<T> list) {
    list.sort(null);
}

public static <T extends Object & Comparable<? super T>> T max(Collection<? extends T> coll)

循环比较,也可以传入比较器

public static <T extends Object & Comparable<? super T>> T max(Collection<? extends T> coll) {
    Iterator<? extends T> i = coll.iterator();
    T candidate = i.next();

    while (i.hasNext()) {
        T next = i.next();
        if (next.compareTo(candidate) > 0)
            candidate = next;
    }
    return candidate;
}

排序:

  • sort

查找:

  • binarySearch

最大值最小值

  • max
  • min

Changelog

6/3/25, 1:49 AM
View All Changelog
  • d3a6d-Merge branch 'dev1'on

求求了,快滚去学习!!!

求求了求求了,快去学习吧!

【题单】贪心算法

不知道方向的时候,可以多看看书,书会给你指明下一步该干什么,加油!