collections framework

Collection(s) and Collections Framework in Java

What is Collection ?

A “collection” object sometimes called a container is simply an object that groups multiple elements into a single unit. Collections are used to store, retrieve, manipulate, and communicate aggregate data.

Another meaning for “Collection” is it’s an java.util interface from which Set, List etc., interfaces can extend

What is Collections ?

Collections is a class which holds static collection of utility methods that operate on or return collections. It contains polymorphic algorithms that operate on collections, “wrappers”, which return a new collection backed by a specified collection.

What is Collections Framework ?

A collections framework is a unified architecture for representing and manipulating collections.

All collections framework contain the following

  • Interfaces
  • Implementations
  • Algorithms

What are the benefits of collections framework ?

  • Reduces programming effort.
  • Increases program speed and quality.
  • Allows interoperability among unrelated APIs.
  • Reduce effort to learn and use new APIs.
  • Reduces effort to design new APIs.
  • Fosters software reuse: New data structures that conform to the standard collection interfaces are by nature reusable.

Interfaces

Interfaces or Collection interfaces are abstract data types that represent collections. Collection interfaces are in the form of Java interfaces.

Interfaces allow collections to be manipulated independently of the implementation details of their representation, which is called the polymorphic behavior.

In Java programming language (and other object-oriented languages), interfaces generally form a hierarchy. You choose one that meets your need as a type.

Implementations

Implementations are the data objects used to store collections, which implement the interfaces.

Each of the implementations for general purpose (please check General-purpose implementations section) provide all optional operations contained in its interface.

Java Collections Framework also provides several implementations for special purpose situations that require nonstandard performance, usage restrictions, or other unusual behavior.

Types of Implementations

The types of implementations are:

  • General-purpose implementations
  • Special-purpose implementations
  • Concurrent implementations
  • Wrapper implementations
  • Convenience implementations
  • Abstract implementations

General-purpose implementations

collections general purpose implementations

Algorithms:

These are the methods that perform useful computations, such as searching and sorting, on objects, which implement collection interfaces.

The algorithms are said to be polymorphic that is, the same method can be used on many different implementations of the appropriate collection interface. In essence, algorithms are reusable functionality.

Core Collection Interfaces Hierarchy

The hierarchy of core collection interfaces (highlighted green) are shown in the following figure.

collections hierarchy

Core Collection Interfaces are the foundation of the Java Collections Framework. Core Collection Interfaces form an inheritance hierarchy among themselves. You can also create a new collection interface from them if you want.

References

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments