/Collections.sort(l);
//print(l);

}

public static void print(Collection c){
Iterator it = c.iterator();
while(it.hasNext()){
Object o = it.next();
System.out.println(o);

解决方案 »

  1.   

    就是一个打印Collection中所有元素的例子用System.out.println(c);就可以了
      

  2.   

    用迭代器遍历一个集合对象,然后用Object的toStirng()方法打印出集合内的每一个对象
      

  3.   

    public static void print(Collection c){ //定义一个无返回值的print方法,需要传一个Collection 参数
    Iterator it = c.iterator();//用迭代器Iterator循环遍历Collection c中的每一个元素
    while(it.hasNext()){//如果c中还有元素
    Object o = it.next();//把这个元素赋给Object型的变量o
    System.out.println(o);//把这个元素输出//这段程序的作用就是打印集合c中的每一个元素