
Collection是一个接口,而Collections是 Java 中的一个实用程序类。 Set、List、和Queue是Collection接口的一些子接口,Map接口也是一部分Collections框架的一部分,但它不继承Collection接口。 Collection接口的重要方法有add()、remove()、size()、clear()等,并且Collections类仅包含静态方法,如sort()、min()、max()、fill()、copy()、reverse()等。
集合接口的语法
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











