-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.java
29 lines (23 loc) · 989 Bytes
/
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import java.util.*;
public class Main {
public static void main(String[] args) {
// Set of books sorted by title
Set<Book> bookSetByName = new TreeSet<>();
bookSetByName.add(new Book("Java Programming", 300));
bookSetByName.add(new Book("Python Basics", 250));
bookSetByName.add(new Book("Data Structures", 400));
bookSetByName.add(new Book("Algorithm Design", 350));
bookSetByName.add(new Book("Web Development", 200));
System.out.println("Books sorted by title:");
for (Book book : bookSetByName) {
System.out.println(book);
}
// Set of books sorted by page count
Set<Book> bookSetByPageCount = new TreeSet<>(Comparator.comparingInt(Book::getPageCount));
bookSetByPageCount.addAll(bookSetByName);
System.out.println("\nBooks sorted by page count:");
for (Book book : bookSetByPageCount) {
System.out.println(book);
}
}
}