coleection.sort
package Practice;import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Sort {
public static void main(String args[]){
Student a = new Student();
a.setClasses(1);
a.setId(1);
a.setName("liufei");
a.setScore(100);
Student b = new Student();
b.setClasses(2);
b.setId(1);
b.setName("liu");
b.setScore(100);
List<Student> list = new ArrayList<Student>();
list.add(a); list.add(b);
Collections.sort(list);
for(Student na:list){
System.out.println("na.getName()");
}
}
}
class Student implements Comparable<Student>{
private String name;
private int id;
private int classes;
private int score;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getClasses() {
return classes;
}
public void setClasses(int classes) {
this.classes = classes;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
@Override
public int compareTo(Student o) {
// TODO Auto-generated method stub
return this.getScore().compareTo(o.getScore());//这句话在myeclipse下面显示错误
}
}