top of page

Subscribe to Wisdom

Thanks for Subscribing!

  • Writer's picturePuru Uttam

Collection Vs Collections in Java

What is the difference between Collection and Collections in Java???

This question is bit confusing as they both look similar. Both are the part of Java Collection Framework but there is a major difference between them.


Collection :

  • It is an interface present at the top level in Java Collection framework.

  • Mostly Classes in Java Collection Framework inherits this interface like List, Set and Queue.

  • JDK does not provide any implementation of Collection interface.

  • List, Set and Queue are the main sub-interfaces of Collection Interface which are having their implementation Classes like ArrayList, HashSet and PriorityQueue provided by JDK.

  • It is present in java.util package.

  • It extends Iterable interface present in java.lang package.

  • It contains abstract methods. Some of them are listed below


//some important and widely used methods of Collection
int size()
boolean isEmpty()
boolean contains(Object obj) 
Iterator<E> iterator()
boolean add(E e)
boolean remove(Object obj)
Object[] toArray()
int hashCode()
boolean equals(Object obj)

Collections :

  • It a Util/Utility class present in java.util package.

  • It contains only static methods which are used to perform various operations on objects having type Collection.

  • The methods of this class all throw a NullPointerException if the collections or class objects provided to them are null.

  • It has a private constructor.

private Collections() {
}
  • Here are some static methods listed below which are present in Collections class.

//methods widely used.
Collections.reverse()
Collections.copy()
Collections.sort()
Collections.max()
Collections.min()
Collections.synchronizedCollection()
Collections.replaceAll() 

18 views0 comments

Recent Posts

See All

Comments


Modern Digital Watch
bottom of page