java集合类的一些内建函数分析

来源:互联网 发布:win7 443端口服务 编辑:程序博客网 时间:2024/06/04 18:50

Collection<E>     //Collection内建函数更接近Set因为需要照顾Set,Set没有的高级功能boolean add(Object element)                //addAllboolean remove(Object element)             //removeAll      删除指定位置的元素需要迭代器void clear()int size()boolean isEmpty()boolean contains(Object element)                    comtainsAll(Collection<?> other)Object[] toArray()Iterator<E> iterator()boolean hasNext()E next()void remove()     //无void add()

List<E>void add(int i, E element)             //addAllE remove(int i)E get(int i)E set(int i, E element)int indexOf(Object element)int lastIndexOf(Object element)ListIterator<E> listIterator()       //继承自Iterator,有序集合才能在指定位置addvoid add(E newElement)void set(E newElement)int nextIndex()


Set<E>//基本同CollectionSortedSet<E>E fisrt()E last()

Queue<E>boolean add(E element)    //尾部增加boolean offer(E element)    //满了不会抛出IllegalStateException,而是返回falseE remove()      //头部删除E poll()      //空了不会抛出NoSuchElementException,而是返回nullE element()         //头部读取E peek()           //空了不会抛出NoSuchElementException,而是返回nullDeque<E>void addFirst(E element)void addLast(E element)boolean offerFirst(E element)boolean offerLast(E element)E removeFirst()E removeLast()E pollFirst()E pollLast()E getFirst()E getLast()E peekFirst()E peekLast()


实现分析:
ArrayList最大功能是实现List,所以内建函数和List比较接近
LinkedList全能,所以为了实现最大功能,内建函数和Deque比较接近
ArrayDeque就是为了实现Deque,内建函数基本和Deque接近
HashSet内建函数基本和Set接近,而Set和Collection接近
TreeSet内建函数和SortedSet接近
PriorityQueue比较特殊,继承自Queue父接口,所以基本一样,add,remove,但效果完全不一样,所以定义的时候一般不使用接口定义

原创粉丝点击