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
本文详细介绍了Java集合框架中Collection接口及其子接口List和Set的方法,包括size、isEmpty、contains等通用方法,以及List特有的addAll、get、set等方法。特别强调了ListIterator的使用,它提供了反向迭代集合的能力。
881

被折叠的 条评论
为什么被折叠?



