Collections工具类可以对List集合中的元素排序,但是集合元素必须是可以比较的
public static void main(String[] args) {
//排序
List l = new ArrayList();
l.add(10);
l.add(9);
l.add(30);
/* for(int i = 0 ;i<l.size();i++ ) {
System.out.println(l.get(i));
}*/
/*for(Iterator<E> it = l.iterator();it.hasNext();) {
System.out.println(it.next());
}*/
Collections.sort(l);
Iterator it = l.iterator();
while(it.hasNext()) {
System.out.println(it.next());
}
Set s = new HashSet();
s.add(2);s.add(1);
//Collections.sort(s);不能对set集合进行排序
List LL = new ArrayList(s);
Collections.sort(LL);
}
//将ArrayList集合转换为线程安全的
List m = new ArrayList();
Collections.synchronizedList(m);