- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Difference between collection and collections in java
Java collection framework is used to manipulate the collection of the object. Collection framework contains multiple wrapper classes , convenience class , classes for legacy implementation like vector and Hashtable, collection interfaces and etc.
Collection is an interface in the java collection framework. It is divided into two parts −
- Java util collection - It contains classes such as Set , queue , List and etc.
- Java util map - It contains classes such as Map , sortedMap and etc.
On the other hand , Collections is the one the utility class. Main purpose of this class is to provide convenience method to the developers. This class has only static methods that operate on and return collection. The methods of this class all throw a NullPointerException if the collections or class objects provided to them are null.
Sr. No. | Key | Collection | Collections |
---|---|---|---|
1 | Basic | It is an interface in Java collection framework | It is a utility class in Collection framework |
2 | Static Methods | It doesn't has all static methods | It has all static method |
3 | Operation | It is used to store list of object in a single object | It is used to operate on collection. |
Example of Collection and Collections
import java.util.ArrayList; import java.util.Collections; import java.util.List; public class Main { public static void main(String[] args) { // List List list = new ArrayList(); list.add("HCL"); list.add("DELL"); // Sorting List in ascending order according to the natural ordering Collections.sort(list); list.forEach(System.out::println); } }