printElement(al); 报错 为什么?
java吧
全部回复
仅看楼主
level 7
cgxnjnj 楼主
package List;
import java.util.*;
public class fsdfsd {
public static void printElement(Collection c) {
Iterator it = c.iterator();
while (it.hasNext()) {
System.out.println(it.next());
}
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
/*
* ArrayList al = new ArrayList(); al.add(new Point(3, 3)); al.add(new
* Point(4, 4)); al.add(new Point(5, 5));
*
* System.out.println(al); printElement(al); Iterator it =
* al.iterator(); it.next(); // it.remove(); while (it.hasNext()) {
* System.out.println(it.next());
*
* }
*/
Student s1 = new Student(1, "zhangshan");
Student s2 = new Student(2, "lishi");
Student s3 = new Student(3, "wangwu");
ArrayList al = new ArrayList();
al.add(s1);
al.add(s2);
al.add(s3);
Collections.sort(al);
printElement(al);
}
}
class Student implements Comparable {
int num;
String name;
public Student(int num, String name) {
this.num = num;
this.name = name;
}
@Override
public int compareTo(Object o) {
// TODO Auto-generated method stub
Student s = (Student) o;
return num > s.num ? 1 : (num == s.num ? 0 : -1);
}
public String tostString() {
return num + ":" + name;
}
}
2016年05月01日 06点05分 1
level 5
看的费劲,排下版怎么样,删除注解怎么样,贴出错误信息怎么样?~
2016年05月01日 06点05分 2
放到eclipse里格式化一下,没什么注解,我是在eclipse运行的
2016年05月01日 06点05分
level 5
敢不敢贴出异常信息?
2016年05月01日 08点05分 3
你运行一下我机器关了
2016年05月01日 09点05分
1