java文件中的数据排序
public class Elective {
private String esno; //学号
private String ecno; //课程号
private int egrade; //成绩
public Elective(){
}
学号 课程号 成绩
11403090101 01 98
11403090102 02 88
11403090103 01 77
11403090104 01 100对
在文件中对成绩降序排序,请各位给我具体实现的代码,谢谢
------解决方案--------------------把实体类放到TreeSet集合里,当comparaTo>0时,正常顺序添加
------解决方案--------------------public class Elective implements Comparable {
private String esno;
private String ecno;
private int egrade;
Elective (String esno,String ecno,int egrade) {
this.esno= esno;
this.ecno= ecno;
this.egrade= egrade;
}
@Override
public String toString() {
}
@Override
public int compareTo(Object o) {
return -2;
}
public class TestTreeSet {
public static void main(String[] args) {
ATreeSet a1 = new ATreeSet();
ATreeSet a2 = new ATreeSet();
ATreeSet a3 = new ATreeSet();
TreeSet t = new TreeSet();
t.add(a1);
t.add(a3);
t.add(a2);
System.out.println(t);
}
}
------解决方案--------------------仅供参考:
import java.util.*;
import java.io.*;
public class SortStoreFile{
public static void main(String[] args){
try{
BufferedReader bf = new BufferedReader(new FileReader("d:\\score.txt"));//打开文件读