实现类:
List: ArrayList、LinkedList
Set: HashSet、LinkedHashSet、TreeSet
Map: EnumMap、IdentityHashMap、HashMap、LinkedHashMap、WeakHashMap、TreeMap
Queue: PriorityQueue、LinkedList、ArrayQueue
包含的方法:
int size(); //返回集合元素的个数(不会大于Integer.MAX_VALUE)
boolean isEmpty(); //如果为空 返回true
boolean contains(Object o); //比较集合中是否存在对象o ,如果o的类型和集合中元素类型不匹配,抛出异常 ClassCastException
Iterator<E> iterator();//返回对象的迭代器
Object[] toArray();
<T> T[] toArray(T[] a);
boolean add(E e);
boolean remove(Object o);
boolean containsAll(Collection<?> c);
boolean addAll(Collection<? extends E> c);
boolean removeAll(Collection<?> c);
/**
JDK1.8新添加,删除集合中符合过滤条件的元素
Predicate 的使用详情请看
*/
default boolean removeIf(Predicate<? super E> filter) {
Objects.requireNonNull(filter);
boolean removed = false;
final Iterator<E> each = iterator();
while (each.hasNext()) {
if (filter.test(each.next())) {
each.remove();
removed = true;
}
}
return removed;
}