
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Differences Between Collection and Collections in Java
The Collection is an interface whereas Collections is a utility class in Java. The Set, List, and Queue are some of the subinterfaces of Collection interface, a Map interface is also part of the Collections Framework, but it doesn't inherit Collection interface.
The important methods of Collection interface are add(), remove(), size(), clear() etc and Collections class contains only static methods like sort(), min(), max(), fill(), copy(), reverse() etc.
Syntax for Collection Interface
public interface Collection<E> extends Iterable<E>
Syntax for Collections Class
public class Collections extends Object
Example
import java.util.*; public class CollectionTest { public static void main(String args[]) { ArrayList<Integer> list = new ArrayList<Integer>(); // Adding elements to the ArrayList list.add(5); list.add(20); list.add(35); list.add(50); list.add(65); // Collections.min() method to display minimum value System.out.println("Minimum value: " + Collections.min(list)); // Collections.max() method to display maximum value System.out.println("Maximum value: " + Collections.max(list)); } }
Output
Minimum value: 5 Maximum value: 65
Advertisements