1 / 13

Chapter10

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.

mccaslin
Télécharger la présentation

Chapter10

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter10 Collections

  2. 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).

  3. Collections Framework ●A collections framework is a unified architecture for representing and manipulating collections.

  4. All collections frameworks contain three things Interfaces Implementations Algorithms

  5. 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.

  6. Implementations: concrete implementations of the collection interfaces. In essence, these are reusable data structures.

  7. 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.

  8. 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

  9. 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.

  10. The core collections interfaces are shown below:

  11. Collection Map List Set SortedSet SortedMap AbstractCollection AbstractList AbstractSet AbstractMap AbstractSequentialList ArrayList LinkedList HashSet TreeSet HashMap TreeMap Collections Framework

  12. 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.

  13. *参见程序运行

More Related