CoreJava/exp8/TreeSetDemo.java
2024-05-09 09:10:51 +08:00

25 lines
449 B
Java

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);
}
});
}