Collection和Collections

2019-05-07 11:03:42 浏览数 (1)

Collection接口:

代码语言:javascript复制
int size();
boolean isEmpty();
boolean contains();
Iterator<E> iterator();
Object[] toArray();
<T> T[] toArray(T[] a);
boolean add(E e);
boolean remove(Object o);
boolean containsAll(Collection<?> c);
boolean addAll(Colletion<? extends E> c);
boolean removeAll(Collection<?> c);
boolean removeIf(Predicate<? super E> filter);
boolean retainAll(Collection<?> c);
void clear();
boolean equals(Object o);
int hashCode();
default Spliterator<E> spliterator();
default Stream<E> stream();
default Stream<E> parallelStream();

Collections

代码语言:javascript复制
public static <T extends Comparable<? super T>> void sort(List<T> list) ;
public static <T> void sort(List<T> list, Comparator<? super T> c) ;
public static <T> int binarySearch(List<? extends Comparable<? super T>> list, T key) ;
private static <T> int indexedBinarySearch(List<? extends Comparable<? super T>> list, T key);
private static <T> int iteratorBinarySearch(List<? extends Comparable<? super T>> list, T key);
private static <T> T get(ListIterator<? extends T> i, int index);
public static <T> int binarySearch(List<? extends T> list, T key, Comparator<? super T> c);
private static <T> int indexedBinarySearch(List<? extends T> l, T key, Comparator<? super T> c);
private static <T> int iteratorBinarySearch(List<? extends T> l, T key, Comparator<? super T> c);
public static void reverse(List<?> list);
public static void shuffle(List<?> list);
public static void shuffle(List<?> list, Random rnd);
public static void swap(List<?> list, int i, int j);
private static void swap(Object[] arr, int i, int j);
public static <T> void fill(List<? super T> list, T obj);
public static <T> void copy(List<? super T> dest, List<? extends T> src);
public static <T extends Object & Comparable<? super T>> T min(Collection<? extends T> coll);
public static <T> T min(Collection<? extends T> coll, Comparator<? super T> comp);
public static <T extends Object & Comparable<? super T>> T max(Collection<? extends T> coll);
public static <T> T max(Collection<? extends T> coll, Comparator<? super T> comp);
...

Collection是集合顶级接口。提供了对集合对象的基本操作的接口方法。Collections是一个工具类,包含各种有关集合的静态多态方法,包括排序、搜索以及线程安全等各种操作,服务于Java的Collection框架。

0 人点赞