编程红宝书(珍藏版) ava 完金自学手册 6.2.1 Collection接口定义与应用 Collection代表一组对象,这些对象称为它的元素。 Collection 是容器继承树中的顶层接口,作为接口它定义了15个方法,但没 有提供具体实现。 Collection接口如下所示: 1 public interface Collection<E> extends Iterable<E>t 2口的基本操作 nt size 4 boolean is Emptyo 5 boolean contains(Object element); 6 boolean add(E elements) 7 boolean remove(object element) 8 Iterator<E> iterator 9 boolean equals(object element 11∥12到16行为Buk操作 12 boolean containsAll(Collections?> c); 13 boolean addAll( Collection<? extend E>c); 14 boolean removeAll( Collection<?> c);" 15 boolean retainAll( Collection<?> c); 16 void clear 17∥以下为数组操作 18 Objectl toArrayO 19T≥ TI toArray(Ta); Q想桃工业出隙
6.2.1 Collection接口定义与应用 • Collection代表一组对象,这些对象称为它的元素。Collection 是容器继承树中的顶层接口,作为接口它定义了15个方法,但没 有提供具体实现。Collection接口如下所示:
编程红宝书(珍藏版) ava 完金自学手册 6.2.2Map接口定义与应用 Map是一个将键映射到值的对象,映射不能包含重复的键,即每个 键最多可以映射到一个值,这种映射类似于数学中的函数。Map接 口如下所示: 1∥声明map按口 2 public interface Map<K, V>( 3 int size 0: 4 boolean is Empty 0 5 boolean containsKey(object key); A 6 7 V get(object key);" 8 V puto key, K value); 9 V remove(object key) 10∥ Bulk Operation tAll(Map t) 12 void clear 13∥集合视图 14 public Set<K> key seto 15 public Collection<V> values; 16 public Set <Map. EntrysK, V>> entry seto; 17 /nterface for entry Set elements 18 public interface Entry 19 K getKeyo V getvalue 0 V setvalue(V value) Q想桃工业出隙社
6.2.2 Map接口定义与应用 • Map是一个将键映射到值的对象,映射不能包含重复的键,即每个 键最多可以映射到一个值,这种映射类似于数学中的函数。Map接 口如下所示: