25 lines
449 B
Java
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);
|
||
|
}
|
||
|
});
|
||
|
|
||
|
}
|