Skip to main content

Introduction to Java Collection API

·314 words·2 mins

The Java Collections API provide Java developers with a set of classes and interfaces that makes it easier to work with collections of objects, e.g. lists, maps, stacks etc.

classDiagram
    direction TB
    Iterable <|-- Collection

    Collection <|-- List
    Collection <|-- Set
    Collection <|-- Queue

    List <|-- ArrayList
    List <|-- LinkedList
    List <|-- Vector

    Set <|-- HashSet
    Set <|-- LinkedHashSet
    Set <|-- TreeSet

    Queue <|-- PriorityQueue
    Queue <|-- Deque

    Deque <|-- ArrayDeque
    Deque <|-- LinkedList

    classDiagram
    Map <|-- HashMap
    Map <|-- LinkedHashMap
    Map <|-- TreeMap
    Map <|-- Hashtable

Java Iterator
#

The Java Iterator interface represents an object capable of iterating through a collection of Java objects, one object at a time. To use a Java Iterator you will have to obtain an Iterator instance from the collection of objects you want to iterate over. The obtained Iterator keeps track of the elements in the underlying collection to make sure you iterate through all of them.

Java Iterable
#

The Java Iterable interface represents a collection of objects which is iterable, meaning which can be iterated. This means, that a class that implements the Java Iterable interface can have its elements iterated.

Java Collections Class
#

The Java Collections class, java.util.Collections, contains a long list of utility methods for working with collections in Java.

Java List
#

The Java List interface, java.util.List, represents an ordered sequence of objects. The elements contained in a Java List can be inserted, accessed, iterated and removed according to the order in which they appear internally in the Java List.

The following List implementations in the Java Collections API are available:

  • java.util.ArrayList
  • java.util.LinkedList
  • java.util.Vector
  • java.util.Stack

Java Set
#

The Java Set interface, java.util.Set, represents a collection of objects where each object in the Java Set is unique. The Set interface does not gurantee insertion order.

The following Set implementations in the Java Collections API are available:

  • java.util.EnumSet
  • java.util.HashSet
  • java.util.LinkedHashSet
  • java.util.TreeSet
Vaibhav
Author
Vaibhav
Full Stack Developer