CoreJava/exp8/TreeSetDemo.java

25 lines
449 B
Java
Raw Normal View History

2024-05-09 09:10:51 +08:00
package exp8;
import java.util.Comparator;
import java.util.TreeSet;
class Roomate{
String name;
int age;
Roomate(String name, int age){
this.name = name;
this.age = age;
}
}
public class TreeSetDemo {
TreeSet<Roomate> rs = new TreeSet<>(new Comparator<Roomate>() {
@Override
public int compare(Roomate r1, Roomate r2){
return Integer.compare(r1.age, r2.age);
}
});
}