Java Collection, List, Set, Map

最近上课学习了java 的这几个接口,在整理笔记,下贴上已经写的,不全,比如spliterator就没弄明白.

Interface Collection<E>
public interface Collection<E> extends from Iterable<E>
The root interface in the collection hierarchy.
JDK does not provide any direct implementations of this interface
 
Methods:
size : int size();
isEmpty: boolean isEmpty();
contains: boolean contains(Object o) Throws: ClassCastException, NullPointerException
containsAll: boolean containsAll(Collection<?> c) //need to rewrite equals() method
iterator: Interator<E> iterator();
toArray: Object[] toArray();
<T> T[] toArray(T[] a) throws ArrayStoreException , NullPointerException; //String[] y = x.toArray(new String[0]), Build a new Array if T[] is too small
add: boolean add(E e) Throws:
UnsupportedOperationException - if the add operation is not supported by this collection
ClassCastException - if the class of the specified element prevents it from being added to this collection
NullPointerException - if the specified element is null and this collection does not permit null elements
IllegalArgumentException - if some property of the element prevents it from being added to this collection
IllegalStateException - if the element cannot be added at this time due to insertion restrictions
addAll: boolean addAll(Collection<? extends E> c)
remove: boolean remove(Object o) throws: ClassCastException, NullPointerException. UnsupportedOperationException
boolean removeAll(Collection<?> c)
clear: void clear() Throws UnsupportedOperationException;
equals: boolean equals(Object o)
hashCode: int hashCode();
 
Interface List<E>
public Interface List<E> extends from Collection<E>
An ordered collection (at added order)
Allow duplicate elements, null elements,
 
Methods:
Iterator<E> iterator(); returns an iterator over the elements int this list
sort: default void sort(Comparator <? super E> c) Throws :ClassCastException, UnsupportedOperationException
get: E get( int index) Throws: IndexOutOfBoundsException;
set: E set(int index, E element) Throws: the same as add;
add: void add(int index, E element);
remove: E remove(int index); Throws: UnsupportedOperationException, IndexOutOfBoundsException;
indexOf: int indexOf(Object o):Throws ClassCastException, NullPointerException;
int lastIndexOf(Object o);
ListIterator<E> listIterator() ; returns a list interator over the elements in this list
listIterator(int index); Throws: IndexOutOfBoundsException;
subList: List<E> subList(int fromIndex, int toIndex); get subList of this List; Throws: IndexOutOfBoundsException
 
implementing classes:
ArrayList: 底层由数组结构实现,查询快速,增删效率低
LinkedList:底层链表实现,增删快,查询慢
Stack
Vector
 

猜你喜欢

转载自www.cnblogs.com/zhangyue123/p/9286319.html
今日推荐