|
Java-Collections-Framework Seminar
|
|
12-14-2010, 04:25 AM
Post: #1
|
||||
|
||||
|
Java-Collections-Framework Seminar
Objectives
To describe the Java Collections Framework hierarchy (§22.1). To use the common methods defined in the Collection interface for operating sets and lists (§22.2). To use the Iterator interface to traverse a collection (§22.3). To use the JDK 1.5 foreach loop to simplify traversing a collection (§22.3). To discover the Set interface, and know how and when to use HashSet, LinkedHashSet, or TreeSet to store elements (§22.3). To compare elements using the Comparator interface (§22.4). To explore the List interface, and know how and when to use ArrayList or LinkedList to store elements (§22.5). To know how to use the static methods in the Collections class for lists and collections (§22.6). To distinguish Vector and ArrayList, and know how to use Vector and Stack (§22.7). To explore the relationships among Collection, Queue, LinkedList, and PriorityQueue and to create priority queues using the PriorityQueue class (§22.8). To understand the differences between Collection and Map, and know how and when to use HashMap, LinkedHashMap, and TreeMap to store values associated with keys (§22.9). To obtain singleton sets, lists, and maps, and unmodifiable sets, lists, and maps using the static methods in the Collections class (§22.10). Java Collection Framework hierarchy A collection is a container object that represents a group of objects, often referred to as elements. The Java Collections Framework supports three types of collections, named sets, lists, and maps. Java Collection Framework hierarchy, cont. Set and List are subinterfaces of Collection. Java Collection Framework hierarchy, cont. An instance of Map represents a group of objects, each of which is associated with a key. You can get the object from a map using a key, and you have to use a key to put the object into the map. The Collection Interface The Collection interface is the root interface for manipulating a collection of objects. The Set Interface The Set interface extends the Collection interface. It does not introduce new methods or constants, but it stipulates that an instance of Set contains no duplicate elements. The concrete classes that implement Set must ensure that no duplicate elements can be added to the set. That is no two elements e1 and e2 can be in the set such that e1.equals(e2) is true. The Set Interface Hierarchy The AbstractSet Class The AbstractSet class is a convenience class that extends AbstractCollection and implements Set. The AbstractSet class provides concrete implementations for the equals method and the hashCode method. The hash code of a set is the sum of the hash code of all the elements in the set. Since the size method and iterator method are not implemented in the AbstractSet class, AbstractSet is an abstract class. The HashSet Class The HashSet class is a concrete class that implements Set. It can be used to store duplicate-free elements. For efficiency, objects added to a hash set need to implement the hashCode method in a manner that properly disperses the hash code. |
||||
|
« Next Oldest | Next Newest »
|
![]() |
|||||||
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
|
User(s) browsing this thread: 1 Guest(s)
Search
Member List
Calendar
Help




![[-] [-]](images/collapse.gif)






