Collection is an interface and Collections is a utility class in Java. Set, List, and Queue are some sub-interfaces of the Collection interface, and the Map interface is also part of the Collections framework part, but it does not inherit the Collection interface. The important methods of the Collection interface are add(), remove(), size(), clear(), etc., and the Collections class only contains static Methods, such as sort(), min(), max(), fill(), copy(), reverse(), etc.
public interface Collection<E> extends Iterable<E>
public class Collections extends Object
import java.util.*; public class CollectionTest { public static void main(String args[]) { <strong> </strong>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); <strong> </strong>// Collections.min() method to display minimum value<strong> </strong> System.out.println("Minimum value: " + Collections.min(list)); <strong> </strong>// Collections.max() method to display maximum value<strong> </strong> System.out.println("Maximum value: " + Collections.max(list)); } }
Minimum value: 5 Maximum value: 65
The above is the detailed content of What is the difference between Collection and Collections in Java?. For more information, please follow other related articles on the PHP Chinese website!