13 Collections Framework
This presentation is the property of its rightful owner.
Sponsored Links
1 / 18

13 Collections Framework PowerPoint PPT Presentation


  • 56 Views
  • Uploaded on
  • Presentation posted in: General

13 Collections Framework. Contents. What is Collection? Collections Framework Collections Hierarchy Collections Implementations Set List Map. Objectives. Define a collection Describe the collections framework Describe the collections hierarchy

Download Presentation

13 Collections Framework

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


13 collections framework

13 Collections Framework


Contents

Contents

  • What is Collection?

  • Collections Framework

  • Collections Hierarchy

  • Collections Implementations

    • Set

    • List

    • Map


Objectives

Objectives

  • Define a collection

  • Describe the collections framework

  • Describe the collections hierarchy

  • Demonstrate each collection implementation


What is a collection

What is a Collection?

  • A Collection (also known as container) is an object that contains a group of objects treated as a single unit.

  • Any type of objects can be stored, retrieved and manipulated as elements of collections.


Collections framework

Collections Framework

  • Collections Framework is a unified architecture for managing collections

    Main Parts of Collections Framework

    • Interfaces

      • Core interfaces defining common functionality exhibited by collections

    • Implementations

      • Concrete classes of the core interfaces providing data structures

    • Operations

      • Methods that perform various operations on collections


Collections framework interfaces

Collections FrameworkInterfaces


Collections framework implementations

Collections FrameworkImplementations

Note: Hashtable uses a lower-case “t”


Collections framework operations

Collections FrameworkOperations

Basic collection operations:

  • Check if collection is empty

  • Check if an object exists in collection.

  • Retrieve an object from collection

  • Add object to collection

  • Remove object from collection

  • Iterate collection and inspect each object

  • Each operation has a corresponding method implementation for each collection type


  • Collections characteristics

    Collections Characteristics

    • Ordered

      • Elements are stored and accessed in a specific order

    • Sorted

      • Elements are stored and accessed in a sorted order

    • Indexed

      • Elements can be accessed using an index

    • Unique

      • Collection does not allow duplicates


    Iterator

    Iterator

    • An iterator is an object used to mark a position in a collection of data and to move from item to item within the collection

      Syntax:

      Iterator <variable> = <CollectionObject>.iterator();


    Collections hierarchy set and list

    Collection

    implements

    extends

    extends

    Set

    List

    implements

    implements

    HashSet

    SortedSet

    implements

    ArrayList

    Vector

    LinkedList

    LinkedHashSet

    TreeSet

    Collections HierarchySet and List


    Collections hierarchy map

    Map

    extends

    extends

    implements

    SortedMap

    implements

    TreeMap

    Hashtable

    HashMap

    LinkedHashMap

    Collections HierarchyMap


    Collection implementations

    Collection Implementations

    List: Lists of things (classes that implement List)

    Set: Unique things (classes that implement Set)

    Map: Things with a unique ID (classes that implement Map)

    Next!


    13 collections framework

    “Paul”

    “Mark”

    “Luke”

    “John”

    “Paul”

    value

    index

    3

    1

    4

    2

    0

    List

    A List cares about the index.

    ArrayList

    Vector

    LinkedList


    13 collections framework

    Set

    A Set cares about uniqueness, it doesn’t allow duplicates.

    “John”

    “Luke”

    “Paul”

    “Mark”

    “Fred”

    “Peter”

    HashSet

    LinkedHashSet

    TreeSet


    13 collections framework

    Map

    A Map cares about unique identifiers.

    “ul”

    key

    value

    “Ma”

    “Le”

    “Jn”

    “Pl”

    “Paul”

    “Mark”

    “Luke”

    “John”

    “Paul”

    Hashtable

    LinkedHashMap

    TreeMap

    HashMap


    Collection classes summary

    Class

    Map

    Set

    List

    Ordered

    Sorted

    HashMap

    X

    No

    No

    Hashtable

    X

    No

    No

    TreeMap

    X

    Sorted

    By natural order or custom comparison rules

    LinkedHashMap

    X

    By insertion order or last access order

    No

    HashSet

    X

    No

    No

    TreeSet

    X

    Sorted

    By natural order or custom comparison rules

    LinkedHashSet

    X

    By insertion order or last access order

    No

    ArrayList

    X

    By index

    No

    Vector

    X

    By index

    No

    LinkedList

    X

    By index

    No

    Collection Classes Summary


    Key points

    Key Points

    • Collections Framework contains:

      • Interfaces

      • Implementations

      • Operations

  • A list cares about the index.

  • A set cares about uniqueness, it does not allow duplicates.

  • A map cares about unique identifiers.


  • Login