What is the Difference Between Collection and Collections

The main difference between Collection and Collections is that Collection is the root interface of Java Collections Framework while Collections is a utility class which is a member of the Java Collections Framework.

Collection and Collections are widely used in Java programming. Both Collection and Collections are available in java.util package. Collection is the topmost interface while Collection is a class in the Java Collection framework. Overall, Collection allows storing multiple objects as one Collection object. On the other hand, Collections allow performing operations on that object.

Key Areas Covered

1. What is Collection
     – Definition, Functionality
2. What is Collections
     – Definition, Functionality
3. What is the Difference Between Collection and Collections
     – Comparison of Key Differences

Key Terms

Collection, Collections, Java

Difference Between Collection and Collections - Comparison Summary

What is Collection

Collection is the root interface of the Java Collection framework. It has many sub-interfaces such as List, Set, etc. Map interface also belongs to the collection framework, but it does not inherit from Collection interface. Collection extends from an Interface called Iterator and obtains all functionalities of that interface.

Difference Between Collection and Collections

All the methods of Collection interface are public and abstract. Some common methods are as follows.

boolean add() – Allows inserting a specific element to the collection

boolean addAll(Collection c) – Allows adding all the elements to the collection

clear() – Removes all the elements from the collection

boolean isEmpty() – Helps to find whether the collection is empty or not

int size() – Helps to find the number of elements in the collection

boolean contains(Object o) – Checks whether the collection contains a specified object

boolean remove(Object o) – Removes a specified instance from the collection

What is Collections

“Collections” is a utility class of the Java Collection framework. It has static methods that allow performing operations on the objects of the type Collection. Some common methods in the Collection class are as follows.

Collections.max() – Helps to find the maximum value present in the collection

Collection.min() – Helps to find the maximum value present in the collection

Collection.sort() – Allows sorting the elements of the collection

Collection.copy() – Helps to copy elements of one collection into some other collection

Collection.reverse() – Allows reversing the order of the elements in the collection

Collections.binarySerach() – Helps to search an element using the binary search algorithm

Difference Between Collection and Collections

Definition         

Collection is the parent interface of all other child interfaces and classes of the Java Collection framework while Collections is a utility class of Java Collection framework that consists of static utility functions. Thus, this is the main difference between Collection and Collections.

Consist of

Moreover, another difference between Collection and Collections is that Collection consists of sub-interfaces such as List, Set, and Queue while Collections consist of static utility methods such as sort, reverse, etc.

Usage

Furthermore, Collection helps to store a set of objects into a single Collection object while Collections helps to perform an operation on the object of Collection. Hence, this is also a difference between Collection and Collections.

Conclusion

There is a distinct difference between Collection and Collections although most people use these two terms interchangeably. The main difference between Collection and Collections is that Collection is the root interface of Java Collections Framework while Collections is a utility class which is a member of the Java Collections Framework. In brief, Collection is an interface whereas Collections is a class.

Reference:

1. “Interface Java.util.Collection.” Courses.cs.washington.edu, Available here.

Image Courtesy:

1. “Java collection interfaces” By Original version created by b:User:Ervinn, SVG version created by myself – Own work (CC BY-SA 2.5) via Commons Wikimedia

About the Author: Lithmee

Lithmee holds a Bachelor of Science degree in Computer Systems Engineering and is reading for her Master’s degree in Computer Science. She is passionate about sharing her knowldge in the areas of programming, data science, and computer systems.

Leave a Reply