Java collections

https://www.geeksforgeeks.org/collections-in-java-2/?ref=lbp

Collection

  • Any group of individual objects which are represented as a single unit

Collection Framework

  • defined in JDK 1.2

  • holds all the collection classes and interface

! The Collection interface (java.util.Collection ) and Map interface (java.util.Map ) are the two main โ€œrootโ€ interfaces of Java collection classes.

Framework

Advantages of the Collection Framework

  • Consistent API

  • Reduces programming effort

  • Increase program speed and quality

Hierarchy of the Collection Framework

  • Class

    • user-defined blueprint or prototype from which objects are created

    • represents the set of properties or methods that are common to all objects of one type

  • Interface

    • Like a class, an interface can have methods and variables, but the methods declared in an interface are by default abstract (only method signature, no body)

    • pecify what a class must do and not how

    • blueprint of the class

Methods of the Collection Interface

This interface contains various methods which can be directly used by all the collections which implement this interface.

Interfaces that extend the Collections Interface

The collection framework contains multiple interfaces where every interface is used to store a specific type of data.

The following are the interfaces present in the framework.

  1. Iterable Interface

    • root interface for the entire collection framework

    • all the interfaces and classes implement this interface

    • the main functionality of this interface is to provide an iterator for the collections

    // this interface contains only one abstract method which is the iterator
    Iterator iterator();
  2. Collection Interface

  3. List Interface

    1. ArrayList

    2. LinkedList

    3. Vector

    4. Stack

  4. Queue Interface

    1. Priority Queue

  5. Deque Interface

    1. ArrayDeque

  6. Set Interface

    1. HashSet

    2. LinkedHashSet

  7. Sorted Set Interface

    1. TreeSet

  8. Map Interface

    1. HashMap

What You Should Learn in Java Collections?

reference

Last updated