测试类
public class Test_Student02 {
public static void main(String[] args) {
List<Student02> list = new ArrayList<>();
String s = "张三-男-18|李四-男-19|王五-女-20|赵六-女-17";
String[] split = s.split("[|]");
for (String s1 : split) {
String[] split1 = s1.split("[-]");
list.add(new Student02(split1[0],split1[1],Integer.parseInt(split1[2])));
}
Collections.sort(list, new Comparator<Student02>() {
@Override
public int compare(Student02 o1, Student02 o2) {
int a = o1.getFs()-o2.getFs();
return a;
}
});
for (Student02 student02 : list) {
System.out.println(student02);
}
}
实体类
private String name;
private String xb;
private int fs;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getXb() {
return xb;
}
public void setXb(String xb) {
this.xb = xb;
}
public int getFs() {
return fs;
}
public void setFs(int fs) {
this.fs = fs;
}
public Student02() {
}
public Student02(String name, String xb, int fs) {
this.name = name;
this.xb = xb;
this.fs = fs;
}
@Override
public String toString() {
return "Student02{" +
"name='" + name + '\'' +
", xb='" + xb + '\'' +
", fs=" + fs +
'}';
}
运行结果


786

被折叠的 条评论
为什么被折叠?



