一、将Person类中按学号、姓名、年龄排序
实体类
package com.jredu.oop.ch02;
/**
* 实体类
* @author Administrator
*
*/
/**
* Comparable实现排序功能
* @author Administrator
*
*/
public class Person implements Comparable<Person>{
private int id;//编号
private String name;//姓名
private int age;//年龄
public Person(int id, String name, int age) {
super();
this.id = id;
this.name = name;
this.age = age;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
@Override//重写toString方法
public String toString() {
return "Person [id=" + id + ", name=" + name + ", age=" + age + "]";
}
打印
按姓名排序
打印
按年龄排序
打印