30.Camparable
发表日期:2022-08-05 16:54:10 | 来源: | | 浏览(910) 分类:JAVA基础
CamparableDemo01
class Student implements Comparable<Student>{
private String name;
private int age;
private float score;
public Student(String name,int age,float score){
this.name = name;
this.age = age;
this.score = score;
}
public String toString(){
return name + "\t\t" + this.age + "\t\t" + this.score;
}
public int compareTo(Student stu){
if(this.score>stu.score){
return -1;
}else if(this.score<stu.score){
return 1;
}else{
if(this.age>stu.age){
return 1;
}else if(this.age<stu.age){
return -1;
}else{
return 0;
}
}
}
}
public class CamparableDemo01 {
public static void main(String args[]) {
Student stu[] = {
new Student("张三",20,90.0f),
new Student("李四",21,92.0f),
new Student("王五",24,88.3f),
new Student("赵六",19,86.1f),
new Student("孙七",23,76.1f)
};
for(int i=0;i<stu.length;i++){
System.out.println(stu[i]);
}
java.util.Arrays.sort(stu);
System.out.println("<<<<<<Campare>>>>>>");
for(int i=0;i<stu.length;i++){
System.out.println(stu[i]);
}
}
}- JAVA(0)
- JAVA基础(30)
- 1.JAVA开发环境配置(0)
- 2.java数据类型(0)
- 3.数组(0)
- 4.Date(0)
- 5.String 和 StringBuffer类常用方法(0)
- 6.Math类(0)
- 7.Cloneable(0)
- 8.File 文件(0)
- 9.FileReader和FileWriter(0)
- 10.RandomAccessFile(0)
- 11.FileInputStream和FileOutputStream(0)
- 12.InputStreamReader和OutputStreamWriter(0)
- 13.BufferedReader(0)
- 14.Scanner(0)
- 15.DataOutputStream(0)
- 16.Thead 多线程(0)
- 17.TimerTask(0)
- 18.zip(0)
- 19.Charset(0)
- 20.List(0)
- 21.Map(0)
- 22.Properties(0)
- 23.Enumeration(0)
- 24.Collection(0)
- 25.JDBC(0)
- 26.Iterator(0)
- 27.Abstract(0)
- 28.Interface(0)
- 29.Serializable(0)
- 30.Camparable(0)
- JSP基础(50)
宁公网安备 64010402001209号