Introduction to Collections

The Java Collections Framework (JCF) is a set of classes and interfaces that implement commonly reusable collection data structures. The JCF is part of the Java Standard Library, which provides data structures and algorithms for storing and manipulating groups of objects. It is a unified architecture for representing and manipulating collections, allowing collections to be manipulated independently of the details of their representation.

Why Use the Java Collections Framework?

  1. Standardization: The JCF provides standard interfaces and implementations, ensuring consistency across different parts of your application.
  2. Reusability: Common data structures like lists, sets, and maps are provided, which can be reused across applications, reducing the need to implement them from scratch.
  3. Performance: The JCF classes are optimized for performance, allowing for efficient data manipulation.
  4. Interoperability: Collections can work with Java's powerful Stream API for functional-style operations on collections.

What are the differences between Collection and Collections?

  • Collection
    • It the part of java.util package.
    • The root interface in the collection hierarchy. It represents a group of individual objects as a single entity known as its elements.
    • The collection interface is a part of the core framework that provides the base for all the collection types. It defined the most common methods which are applicable for any collection object.
  • Collections
    • It the part of java.util package.
    • Contains static methods that operate on or return collections. It is a utility class that provides methods for manipulating collections, such as sorting, searching, and synchronizing.

Output

Apple
Banana
Orange