java中的collection包下的集合是工作中使用最多的工具包。下面浅析下这些工具包之间的关系以及作用:
1、java.util.Collection<E>
Collection 是列表的最上层抽象。它提供了如下功能:
1、增。add()、addAll()
2、删。remove()、 removeAll(),clear()
3、集合熟悉。size() isEmpty, boolean contains(Object o);boolean containsAll(Collection<?> c);
4、覆盖提醒。int hashCode();boolean equals(Object o);
5、与数组相关。Object[] toArray();<T> T[] toArray(T[] a);
2、public interface List<E> extends Collection<E>
List 列表的抽象。此接口的用户可以对列表中每个元素的插入位置进行精确地控制。用户可以根据元素的整数索引(在列表中的位置)访问元素,并搜索列表中的元素。底层实现为数组。提供的功能有:
1、定点位置的增、删、更新。 这一点和collection抽象的数据有区别
void add(int index, E element);
boolean addAll(int index, Collection<? extends E> c);
E remove(int index);
E set(int index, E element);
2、获取子列表。
List<E> subList(int fromIndex, int toIndex);
3、迭代器相关。
ListIterator<E> listIterator();
4、元素所在的位置。
int indexOf(Object o);
1、java.util.Collection<E>
Collection 是列表的最上层抽象。它提供了如下功能:
1、增。add()、addAll()
2、删。remove()、 removeAll(),clear()
3、集合熟悉。size() isEmpty, boolean contains(Object o);boolean containsAll(Collection<?> c);
4、覆盖提醒。int hashCode();boolean equals(Object o);
5、与数组相关。Object[] toArray();<T> T[] toArray(T[] a);
2、public interface List<E> extends Collection<E>
List 列表的抽象。此接口的用户可以对列表中每个元素的插入位置进行精确地控制。用户可以根据元素的整数索引(在列表中的位置)访问元素,并搜索列表中的元素。底层实现为数组。提供的功能有:
1、定点位置的增、删、更新。 这一点和collection抽象的数据有区别
void add(int index, E element);
boolean addAll(int index, Collection<? extends E> c);
E remove(int index);
E set(int index, E element);
2、获取子列表。
List<E> subList(int fromIndex, int toIndex);
3、迭代器相关。
ListIterator<E> listIterator();
4、元素所在的位置。
int indexOf(Object o);