第13章 对象容器 Collection类 Map类
第13章 • 对象容器 – Collection类 – Map类
简介List界面 Lit界面是 javautil. Collection接口的子接口 Collection界面是」 java. lang Iterable子界面 package java. langi import java.util. Iterator public interface Iterable<r> f Iterator<r> iterator(i 在 Java se的AP中找不到任何实作 terator的类别 terator会根据实际的容器数据结构来迭代元素 而容器的数据结构实作方式对外界是隐藏的
简介List界面 • List界面是java.util.Collection接口的子接口 • Collection界面是java.lang.Iterable子界面 • 在Java SE的API中找不到任何实作Iterator的类别 – Iterator会根据实际的容器数据结构来迭代元素 – 而容器的数据结构实作方式对外界是隐藏的 package java.lang; import java.util.Iterator; public interface Iterable<T> { Iterator<T> iterator(); }
简介List界面 Collection界面继承了 iterator界面 package java. utili public interface Collection<E> extends Iterable<e> t int sizeof boolean isEmpty ()i boolean contains(object o)i Iterator<e> iterator( <T> T[] toArray(T[] a)i boolean add(e o) boolean remove(object o)i boolean containsAll(collection<?> c)i boolean addAll(Collection<? extends E> c)i boolean removeAll( Collection<?> c)i boolean retainAll(collection<?> c) void clear()i boolean equals(object o)i int hashCode (
简介List界面 • Collection界面继承了Iterator界面 package java.util; public interface Collection<E> extends Iterable<E> { int size(); boolean isEmpty(); boolean contains(Object o); Iterator<E> iterator(); <T> T[] toArray(T[] a); boolean add(E o); 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界面 每个加人List中的元素是循序加入的’并可 指定索引来存取元素 package java.util public interface List<e> extends Collection<e> I boolean addAll(int index, Collection<? extends E>c) e get(int index) E set(int index, E element)i void add(int index, E element)i E remove(int index) int indexof(object o)i int lastIndexof(object o)i List<e> sublist(int fromIndex, int toIndex)i
简介List界面 • 每个加入List中的元素是循序加入的,并可 指定索引来存取元素 package java.util; public interface List<E> extends Collection<E> { .... boolean addAll(int index, Collection<? extends E> c); E get(int index); E set(int index, E element); void add(int index, E element); E remove(int index); int indexOf(Object o); int lastIndexOf(Object o); List<E> subList(int fromIndex, int toIndex); .... }
简介List界面 Lit可以使用数组(Aray)或是链结串行 ( Linkedlist)来实作这个特性 对于循序加入与存取,使用 ArrayList的效率 比较好 对于经常变动元素排列顺序的需求,使用 Linkedlist会比较好
简介List界面 • List可以使用数组(Array)或是链结串行 (LinkedList)来实作这个特性 • 对于循序加入与存取,使用ArrayList的效率 比较好 • 对于经常变动元素排列顺序的需求,使用 LinkedList会比较好