Saturday, 1 April 2017

Difference:Collection vs Collections in java

Collection and Collections in java differs based on following parameters:

1.      Basic
Collection is the base interface of java collection framework in java.util package. 
In the below given diagram you can see that Collection is base interface and List, Set, etc extends it.

Collection interface by Java Radar
Collection interface

Collections is a utility class in java.util package.

2.      Purpose
Collection interface is the root of which interface like List, Set, Queue, etc form sub-interface.

Collections class consists of only static methods that can be used to perform operation on objects of type Collection.

For example,

*click each listed example to see programmatic explanation

     In above example you can see that all methods like sort(), binarySearch, etc are static method which can be directly called using class name(Collections). For calling static method you don't need to create instance and thus these methods become simple to use while working on collection classes like array list, linked list, hashset, etc.

You may also like to read:

1 comment:

If you are looking for a reference book on java then we recommend you to go for → Java The Complete Reference
Click on the image link below to get it now.