The Java Collections Framework consists of a number of interfaces and implementations for handling collections and maps. A collection groups multiple elements into a single unit.
A collection can be implemented as either of the classic data structures, lists or sets. A list allows duplicates, and maintains objects in the order in which they are added to the list. On the other hand, a set does not allow duplicates and provides either no particular ordering or an ordering based on the objects themselves regardless of the order in which they were added.
A map is a grouping of keys and their corresponding values. A map cannot contain duplicate keys, and each key can have at most one associated value. An example of a map
is a grouping of employee numbers (key) and the associated employee names (values).
The Collection Framework is a hierarchy of interfaces, as shown in Figure 1. This hierarchy is mirrored in the hierarchy of offered implementations, as shown in Figure 2. Collections provide examples of polymorphism: some operations are defined on all collections, and as collections get more specialized, operations that make sense only for that type are introduced into the hierarchy. We can write code that will manipulate a Collection type. This code will work regardless of the implementation of that Collection type.
The main top-level interfaces in the Collections Framework are Collection and Map. These interfaces define methods typically for adding elements to, removing elements from, and iterating through collections and maps. Sun does not provide a direct implementation of the Collection interface. Two more interfaces are inherited from the Collection
interface: the Set and List interfaces. The SortedSet interface, in turn, inherits from the Set interface. Sun provides classes that implement all these lower-level interfaces. The SortedMap interface inherits from the Map interface; implementations are provided for both the Map and SortedMap interfaces.
A collection can be implemented as either of the classic data structures, lists or sets. A list allows duplicates, and maintains objects in the order in which they are added to the list. On the other hand, a set does not allow duplicates and provides either no particular ordering or an ordering based on the objects themselves regardless of the order in which they were added.
A map is a grouping of keys and their corresponding values. A map cannot contain duplicate keys, and each key can have at most one associated value. An example of a map
is a grouping of employee numbers (key) and the associated employee names (values).
The Collection Framework is a hierarchy of interfaces, as shown in Figure 1. This hierarchy is mirrored in the hierarchy of offered implementations, as shown in Figure 2. Collections provide examples of polymorphism: some operations are defined on all collections, and as collections get more specialized, operations that make sense only for that type are introduced into the hierarchy. We can write code that will manipulate a Collection type. This code will work regardless of the implementation of that Collection type.
The main top-level interfaces in the Collections Framework are Collection and Map. These interfaces define methods typically for adding elements to, removing elements from, and iterating through collections and maps. Sun does not provide a direct implementation of the Collection interface. Two more interfaces are inherited from the Collection
interface: the Set and List interfaces. The SortedSet interface, in turn, inherits from the Set interface. Sun provides classes that implement all these lower-level interfaces. The SortedMap interface inherits from the Map interface; implementations are provided for both the Map and SortedMap interfaces.
No comments:
Post a Comment