标题:coleection.sort
取消只看楼主
不落夕阳
Rank: 2
等 级:论坛游民
帖 子:64
专家分:30
注 册:2016-10-13
结帖率:69.57%
已结贴  问题点数:5 回复次数:0 
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下面显示错误
    }
   
   
}
搜索更多相关主题的帖子: sort List public Student int 
2017-07-22 11:44



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-479542-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013853 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved