[求助]请教一个关于集合类的程序!!
请问一下:1.第x行是怎样给调用的??2.运行到第y行时,它又会跳到哪里运行??
3.怎样进行排序的,即第x行中函数的运算过程??
import java.util.*;
class lianxi
{
static void printElement(Collection c)
{
Iterator I=c.iterator();
while(I.hasNext())
System.out.println(I.next());
}
public static void main(String []args)
{
student s1=new student(2,"xiaoming");
student s2=new student(1,"xiaoqiang");
student s3=new student(3,"xiaojiang");
ArrayList A=new ArrayList();
A.add(s1);
A.add(s2);
A.add(s3);
Collections.sort(A); //第y行
printElement(A);
}
}
class Point
{
int i;
Point(int i)
{
this.i=i;
}
public String toString()
{
return "i="+i;
}
}
class student implements Comparable
{
int num;
String name;
student(int num,String name)
{
this.num=num;
this.name=name;
}
public int compareTo(Object o) //第x行
{
system.out.println("a");
student s=(student)o;
return num>s.num?1:(num==s.num?0:-1);
}
public String toString()
{
return num+":"+name;
}
}
[此贴子已经被作者于2007-10-10 13:27:38编辑过]