Collection: Collection is a interface present in java.util.package. It is used to represent a group of individual objects as a single unit. It is similar to the container in the C++ language. The collection is considered as the root interface of the collection framework. It provides several classes and interfaces to represent a group of individual objects as a single unit.
The List, Set, and Queue are the main sub-interfaces of the collection interface. The map interface is also part of the java collection framework, but it doesn’t inherit the collection of the interface. The add(), remove(), clear(), size(), and contains() are the important methods of the Collection interface.
public interface Collection<E> extends Iterable<E> Type Parameters: E - the type of elements returned by this iterator
Collections: Collections is a utility class present in java.util.package. It defines several utility methods like sorting and searching which is used to operate on collection. It has all static methods. These methods provide much-needed convenience to developers, allowing them to effectively work with Collection Framework. For example, It has a method sort() to sort the collection elements according to default sorting order, and it has a method min(), and max() to find the minimum and maximum value respectively in the collection elements.
public class Collections extends Object
Collection vs Collections:
|It is an interface.||It is a utility class.|
|It is used to represent a group of individual objects as a single unit.||It defines several utility methods that are used to operate on collection.|
|The Collection is an interface that contains a static method since java8. The Interface can also contain abstract and default methods.||It contains only static methods.|
Elements of arrlist before the operations: [geeks, for, geeks] Elements of arrlist after the operations: [geeks, for, geeks, web, site] [for, geeks, geeks, site, web]
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
- Difference between Traditional Collections and Concurrent Collections in java
- Swapping items of a list in Java : Collections.swap() with Example
- Collections.singleton() method in Java with example
- Stack addAll(int, Collection) method in Java with Example
- Stack addAll(Collection) method in Java with Example
- Java.util.Collections.rotate() Method in Java with Examples
- Java.util.Collections.frequency() in Java
- Java.util.Collections.frequency() in Java with Examples
- Java.util.Collections.disjoint() Method in java with Examples
- Collections.sort() in Java with Examples
- Collections.binarySearch() in Java with Examples
- Collections.reverse() in Java with Examples
- Collections.shuffle() in Java with Examples
- Collections.reverseOrder() in Java with Examples
- Output of Java programs | Set 13 (Collections)
- Collections checkedMap() method in Java with Examples
- Need of Concurrent Collections in java
- Collections singletonMap() method in Java with Examples
- Collections min() method in Java with Examples
- Collections.nCopies() in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.