标签:
Colletion是集合接口
Collections是集合工具类,是一个类哈!
public class CollectionsTest { public static void main(String[] args) { List list = new ArrayList(); list.add(4); list.add(3); list.add(9); list.add(3); list.add(10); list.add(1); for (Iterator it = list.iterator() ; it.hasNext() ;){ System.out.println(it.next()); } //对list进行排序 Collections.sort(list); System.out.println("------------"); for (Iterator it = list.iterator() ; it.hasNext() ;){ System.out.println(it.next()); } Set set = new HashSet(); set.add(3); set.add(10); set.add(199); set.add(1); set.add(44); set.add(199); //Sort方法不能对set排序,所以先把Set转换成List List l = new ArrayList(set); Collections.sort(l); System.out.println("------------"); for (Iterator it = l.iterator() ; it.hasNext() ;){ System.out.println(it.next()); } //将ArrayList转换成线程安全的 List syncList = Collections.synchronizedList(list); } }
4
3
9
3
10
1
------------
1
3
3
4
9
10
------------
1
3
10
44
199
标签:
原文地址:http://www.cnblogs.com/i-love-kobe/p/5908097.html