文章目录
package 结构体_对象排序;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class _排序 {
static List<Node> ls = new ArrayList<>();
static Node[] ns = new Node[10005];
public static void main(String[] args) {
Collections.sort(ls);
Arrays.sort(ns);
}
}
class Node implements Comparable<Node>{
int age;
String name;
// 年龄降序,名字字典序升序
public int compareTo(Node node) {
if (this.age>node.age){
return -1;
}else if (this.age<node.age){
return 1;
}else {
return this.name.compareTo(node.name);
}
}
}