Collection vs Collections in Java with Example - GeeksforGeeks

02 Sep, 2020
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.
Declaration:
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.
Declaration:
public class Collections extends Object

Collection vs Collections:                                                           
Java
// Java program to demonstrate the difference  // between Collection and Collections  import java.io.*;import java.util.*;  class GFG {        public static void main (String[] args)     {              // Creating an object of List<String>      List<String> arrlist = new ArrayList<String>();               // Adding elements to arrlist      arrlist.add("geeks");      arrlist.add("for");      arrlist.add("geeks");              // Printing the elements of arrlist      // before operations      System.out.println("Elements of arrlist before the operations:");      System.out.println(arrlist);              System.out.println("Elements of arrlist after the operations:");              // Adding all the specified elements      // to the specified collection      Collections.addAll(arrlist, "web", "site");              // Printing the arrlist after      // performing addAll() method      System.out.println(arrlist);              // Sorting all the elements of the        // specified collection according to       // default sorting order      Collections.sort(arrlist);                // Printing the arrlist after      // performing sort() method      System.out.println(arrlist);              }}
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]


Java-Collections
Difference Between
Java
Java
Java-Collections
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Difference between BFS and DFS
Class method vs Static method in Python
Differences between TCP and UDP
Difference between var, let and const keywords in JavaScript
Difference Between == and .equals() Method in Java
Split() String method in Java with examples
Arrays.sort() in Java with examples
Reverse a string in Java
Initialize an ArrayList in Java
Object Oriented Programming (OOPs) Concept in Java