第 17 章 java 的集合物件
DESCRIPTION
第 17 章 Java 的集合物件. 17-1 集合物件的基礎 17-2 實作 Set 介面的集合類別 17-3 實作 List 介面的集合類別 17-4 實作 Map 介面的集合類別 17-5 輸出集合物件的元素. 17-1 集合物件的基礎. 17-1-1 Java Collections Framework 17-1-2 集合介面 17-1-3 泛型 Java 的集合物件. 17-1-1 Java Collections Framework- 說明. - PowerPoint PPT PresentationTRANSCRIPT
-
17 Java17-1 17-2 Set17-3 List17-4 Map17-5
-
17-1 17-1-1 Java Collections Framework17-1-2 17-1-3 Java
-
17-1-1 Java Collections Framework-CollectionsElementsJavaVectorHashtable
-
17-1-1 Java Collections Framework-1JDK 1.2Java Collections FrameworkCollection InterfaceJavaCollectionSetSortedSetListMapSortedMap
-
17-1-1 Java Collections Framework-2ImplementationsConcrete Classnew
Set
HashSet
SortedSet
TreeSet
List
ArrayListLinkedListVector
Map
HashMapHashtable
SortedMap
TreeMap
-
17-1-1 Java Collections Framework-3Algorithms
-
17-1-2 -Collection InterfaceCollectionMap
-
17-1-2 -Collection()CollectionSetListSetSortedSet
-
17-1-2 -Collection()CollectionCollectionJava Collections FrameworkConcrete ClassSetSetListListSortedSetSetSortedSet
-
17-1-2 -Map()MapCollectionMapSetSortedMap
-
17-1-2 -Map()MapMapKeyValueIPSortedMapSortedSetMapSortedMap
-
17-1-3 Java-JavaGeneric JavaJDK 5.0JavaC++Templates
-
17-1-3 Java-JavaGeneric TypesJavaHashSet hset = new HashSet();HashSet hset = new HashSet();HashSet hset = new HashSet();
-
17-2 Set17-2-1 Set17-2-2 HashSet17-2-3 TreeSet
-
17-2 SetSetCollectionSetSortedSet
-
17-2-1 Set-SetCollection
-
17-2-1 Set-
Set
boolean isEmpty()
true
int size()
boolean add(E)
Etrue
boolean addAll(Collection)
Collectiontrue
boolean remove(Object)
Objecttrue
boolean removeAll(Collection)
Collectiontrue
boolean retainAll(Collection)
Collectiontrue
void clear()
boolean contains(Object)
Objecttrue
boolean containsAll(Collection)
Collectiontrue
-
17-2-2 HashSet-HashSetSetCollectionHash Table
-
17-2-2 HashSet-HashSetJavaHashSetHashSet hset = new HashSet();HashSetString
-
17-2-2 HashSet-
HashSet()
HashSet16
HashSet(int)
HashSetint
HashSet(Collection)
CollectionHashSet
-
17-2-3 TreeSet-TreeSetSortedSetSetSorted Collection
-
17-2-3 TreeSet-TreeSetJavaTreeSetTreeSet tset = new TreeSet();TreeSet
-
17-2-3 TreeSet-
TreeSet()
TreeSet
TreeSet(Collection)
CollectionTreeSet
TreeSet(Comparator c)
TreeSetComparator
TreeSet(SortedSet)
SortedSetTreeSet
-
17-2-3 TreeSet-TreeSetSortedSetSet
SortedSet
E first()
1
E last()
1
SortedSet headSet(E)
ETreeSet
SortedSet subSet(E1, E2)
E1E2TreeSet
SortedSet tailSet(E)
ETreeSet
-
17-3 List17-3-1 List17-3-2 ArrayList17-3-3 LinkedList
-
17-3-1 List-ListCollectionOrdered CollectionOrdered CollectionSorted Collection
-
17-3-1 List-
List
void add(int, E)
intE0
boolean addAll(int, Collection)
intCollectiontrue
E get(int index)
int
int indexOf(Object)
Object1-1
int lastIndexOf(Object)
Object1-1
E remove(int)
int
E set(int, E)
intE
List subList(int, int)
1int2int
-
17-3-2 ArrayList-ArrayListListArrayList
-
17-3-2 ArrayList-JavaArrayListArrayList alist = new ArrayList();ArrayListString
-
17-3-2 ArrayList-
ArrayList()
ArrayList
ArrayList(Collection)
CollectionArrayList
ArrayList(int)
ArrayListint
-
17-3-2 ArrayList-ArrayListList
void ensureCapacity(int)
ArrayListint
void trimToSize()
ArrayList
-
17-3-2 ArrayList-ArrayListJavaforfor ( int i = 0; i < alist.size(); i++ ) System.out.print(alist.get(i)+" ");size()get()ArrayList
-
17-3-3 LinkedList-LinkedListListLinked Lists
-
17-3-3 LinkedList-LinkedListJavaLinkedList
LinkedList()
LinkedList
LinkedList(Collection)
CollectionLinkedList
-
17-3-3 LinkedList-LinkedListList
void addFirst(E)
LinkedList
void addLast(E)
LinkedList
E getFirst()
LinkedList1
E getLast()
LinkedList1
E removeFirst()
LinkedList1
E removeLast()
LinkedList1
-
17-4 Map17-4-1 Map17-4-2 HashMap17-4-3 TreeMap
-
17-4-1 Map-MapSortedMapMap2KeyValue
-
17-4-1 Map-
Set
boolean isEmpty()
true
int size()
V put(K key, V value)
keyvaluekeyvalue
void putAll(Map)
Maptrue
V remove(Object key)
keykeynullvalue
void clear()
boolean containsKey(Object)
Objecttrue
boolean containsValue(Object)
Objecttrue
V get(Object key)
key
Set keySet()
Set
Collection values()
Collection
-
17-4-2 HashMap-HashMapMapHashtable2keynullHashMapJavaHashMapHashMap hmap = new HashMap();HashMap2
-
17-4-2 HashMap-
HashMap()
HashMap16
HashMap(int)
HashMapint
HashMap(Map)
MapHashMap
-
17-4-3 TreeMap-TreeMapSortedMapSortedMapMapJavaStringTreeMapTreeMap tmap = new TreeMap();
-
17-4-3 TreeMap-
TreeMap()
TreeMap
TreeMap(Map)
MapTreeMap
TreeMap(Comparator c)
TreeMapComparator
TreeMap(SortedMap)
SortedMapTreeMap
-
17-4-3 TreeMap-TreeMapSortedMapMap
SortedMap
K firstKey()
1
K lastKey()
1
SortedMap headMap(K)
KTreeMap
SortedMap subMap(K1, K2)
K1K2TreeMap
SortedMap tailMap(K)
KTreeMap
-
17-5 17-5-1 Iterator17-5-2 ListIterator
-
17-5-1 Iterator-IteratorJavaEnumerationCollectionsIteratorCollectionSetListiterator()Iterator
Iterator iterator()
Iterator
-
17-5-1 Iterator-HashSethsetIteratorIterator iterator = hset.iterator();HashSetIteratorString
-
17-5-1 Iterator-
Iteratorwhilewhile (iterator.hasNext()) System.out.print(" "+iterator.next());hasNext()next()
Iterator
boolean hasNext()
true
E next()
void remove()
-
17-5-2 ListIterator-ListIteratorListIteratorIterator
-
17-5-2 ListIterator-ListlistIterator()ListIterator
ListIterator listIterator()
ListIteratorlistIterator(0).
ListIterator listIterator(int)
ListIteratorint1
-
17-5-2 ListIterator-ArrayListalistListIteratorListIterator iterator = alist.listIterator(0);ArrayListListIteratorString
-
17-5-2 ListIterator-
ListIterator
void add(E)
E
boolean hasNext()
true
boolean hasPrevious()
true
E next()
int nextIndex()
E previous()
int previousIndex()
void remove()
void set(E)
E