为什么打出来 是这样的
student@17590db
student@17943a4
student@480457
import java.util.*;
class test2
{
public static void pp(Collection c)
{
Iterator i=c.iterator();
while(i.hasNext())
{
System.out.println(i.next());
}
}
public static void main(String[] args)
{
student s1=new student(1,"wanghai");
student s2=new student(3,"lihai");
student s3=new student(2,"jianghai");
ArrayList a1=new ArrayList();
a1.add(s1);
a1.add(s2);
a1.add(s3);
Collections.sort(a1);
pp(a1);
}
}
class student implements Comparable
{
int num;
String name;
student(int num,String name)
{
this.num=num;
this.name=name;
}
public int compareTo(Object o)
{
student s=(student)o;
return num>s.num ? 1 : (num==s.num ? 0 : -1);
}
public String ToString()
{
return num+":"+name;
}
}