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.
In the below given diagram you can see that Collection is base interface and List, Set, etc extends it.
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,
- Collections.sort()
- Collections.binarySearch()
- Collections.synchronizedCollection()
*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:
Nicely Explained. Thank you
ReplyDelete