你的class实现Comparable接口,并复写compareTo这个函数!!!
比如
class MyProcess implements Comparable{private int priority;
private int id;
private int cpuTime;
private int allTime;
private int startBlock;
private int blockTime;
private boolean state;public MyProcess(int priority,int id,int cpuTime,int allTime,int startBlock,
int blockTime,boolean state){
this.priority=priority;
this.id=id;
this.cpuTime=cpuTime;
this.allTime=allTime;
this.startBlock=startBlock;
this.blockTime=blockTime;
this.state=state;
}public void setPriority(int priority){
this.priority=priority;
}public int getPriority(){
return priority;
}public void setID(int id){
this.id=id;
}public int getID(){
return id;
}public void setCpuTime(int cpuTime){
this.cpuTime=cpuTime;
}public int getCpuTime(){
return cpuTime;
}public void setAllTime(int allTime){
this.allTime=allTime;
}public int getAllTime(){
return allTime;
}public void setStartBlock(int startBlock){
this.startBlock=startBlock;
}public int getStartBlock(){
return startBlock;
}public void setBlockTime(int blockTime){
this.blockTime=blockTime;
}public int getBlockTime(){
return blockTime;
}public void setState(boolean state){
this.state=state;
}public String getState(){
if(state==true){
return "READY";
}
return "BLOCK";
}public String toString(){
return (""+getID()+"        "+getPriority()+"          "+getCpuTime()+"          "+
           getAllTime()+"            "+getStartBlock()+"           "+getBlockTime()+"        "+getState());
}public int compareTo(Object v){
MyProcess other  = (MyProcess)v;
   int i = other.getPriority();
   return priority>i?1:(priority==i?0:-1);
}
}