130 likes | 146 Views
Chapter10. Collections. What Is a Collection? ● A collection is simply an object that groups multiple elements into a single unit. ● sometimes called a container ● Collections are used to store, retrieve and manipulate data, and to transmit data from one method to another.
E N D
Chapter10 Collections
What Is a Collection? ● A collection is simply an object that groups multiple elements into a single unit. ●sometimes called a container ●Collections are used to store, retrieve and manipulate data, and to transmit data from one method to another. ●Collections typically represent data items that form a natural group, like ▲ a poker hand (a collection of cards), ▲ a mail folder (a collection of letters), ▲a telephone directory (a collection of name-to-phone-number mappings).
Collections Framework ●A collections framework is a unified architecture for representing and manipulating collections.
All collections frameworks contain three things Interfaces Implementations Algorithms
Interfaces: abstract data types representing collections. Interfaces allow collections to be manipulated independently of the details of their representation. In object-oriented languages like Java, these interfaces generally form a hierarchy.
Implementations: concrete implementations of the collection interfaces. In essence, these are reusable data structures.
Algorithms: methods that perform useful computations, like searching and sorting, on objects that implement collection interfaces. These algorithms are said to be polymorphic because the same method can be used on many different implementations of the appropriate collections interface. In essence, algorithms are reusable functionality.
the Benefits of a Collections Framework ● It reduces programming effort: ● It increases program speed and quality: ●It allows interoperability among unrelated APIs: ●It reduces the effort to learn and use new APIs: ● It reduces effort to design new APIs: ● It fosters software reuse: By providing useful data structures and algorithms
The core collection interfaces ●The core collection interfaces are the interfaces used to manipulate collections, and to pass them from one method to another. ●The basic purpose of these interfaces is to allow collections to be manipulated independently of the details of their representation. ●The core collection interfaces are the heart and soul of the collections framework.
Collection Map List Set SortedSet SortedMap AbstractCollection AbstractList AbstractSet AbstractMap AbstractSequentialList ArrayList LinkedList HashSet TreeSet HashMap TreeMap Collections Framework
Collection The Collection interface is the root of the collection hierarchy. A Collection represents a group of objects, known as its elements. Some Collection implementations allow duplicate elements and others do not. Set A Set is a collection that cannot contain duplicate elements. List A Listis an ordered collection (sometimes called a sequence). Lists can contain duplicate elements. Map A Mapis an object that maps keys to values. Maps cannot contain duplicate keys: Each key can map to at most one value.