Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) {
- TreeSet<Person> people = new TreeSet<>();
- people.add(new Person(LocalDateTime.of(1987, 5, 14, 0, 0)));
- people.add(new Person(LocalDateTime.of(2000, 5, 14, 0, 0)));
- people.add(new Person(LocalDateTime.of(2002, 5, 14, 0, 0)));
- System.out.println("people: " + people);
- NavigableSet<Person> reversedPeople = people.descendingSet();
- System.out.println("Reversed people: " + reversedPeople);
- }
- public static class Person implements Comparable<Person> {
- private final LocalDateTime birthday;
- public Person(LocalDateTime birthday) {
- this.birthday = birthday;
- }
- @Override
- public int compareTo(Person o) {
- return this.birthday.compareTo(o.birthday);
- }
- @Override
- public String toString() {
- return "Person{" +
- "birthday=" + birthday +
- '}';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement