Java Collections与Collection

来源:互联网 发布:ida远程调试linux 编辑:程序博客网 时间:2024/05/29 18:04

今天参加面试时,遇到一个笔试题,题目如下:Java 中,Collections与Collection的区别是什么。 当时就蒙了,Collections是什么??回来一百度才知道,相当于是为Collection类服务的一个工具类,里面封装了很多有用的静态方法。

小小的一个测试类:

public class Test {public static void main(String[] args) {List<String> co = new ArrayList<String>();co.add("zjh");co.add("test");System.out.println("----Before Sort----");for (String str : co) {System.out.println(str);}Collections.sort(co);System.out.println("----After Sort----");for (String str : co) {System.out.println(str);}}}


0 0
原创粉丝点击