Collection接口

时间:2019-08-22
本文章向大家介绍Collection接口,主要包括Collection接口使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

Collection 接口的方法:

int size();

boolean isEmpty();

boolean contains(Object o);

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);

boolean retainAll(Collection<?> c);

void clear();

boolean equals(Object o);

int hashCode();

子接口List新添的方法:

boolean addAll(int index, Collection<? extends E> c);

E get(int index);

E set(int index, E element);

E set(int index, E element);

E remove(int index);

int indexOf(Object o);

int lastIndexOf(Object o);

ListIterator<E> listIterator(int index);

List<E> subList(int fromIndex, int toIndex);

新添的方法一般都很容易理解需要注意的是listIterator方法,该方法返回一个ListIterator对象,ListIterator接口继承了Iterator接口,提供专门操作List的方法,其新添了void add()

Obeject previous()和boolean hasPrevious(),可以反向迭代集合。

子接口Set未添加新的方法。

继承List接口的ArrayList类和verctor

原文地址:https://www.cnblogs.com/moxia1234/p/4547834.html