Hey I wanted to ask if you could help me with my code.
I have to create five books and save them in a HashSet. Also they are should be sorted by their price, titel and autor (I shoud use a TreeSet for it and implement Comparable in the class) Also I should give the books sorted by their titel, autor and price out (another TreeSet + Comparator).
The main problem is that I'm not sure how to use Comparator so it would be nice if you could help me a little bit this is what I have until now.
I have to create five books and save them in a HashSet. Also they are should be sorted by their price, titel and autor (I shoud use a TreeSet for it and implement Comparable in the class) Also I should give the books sorted by their titel, autor and price out (another TreeSet + Comparator).
The main problem is that I'm not sure how to use Comparator so it would be nice if you could help me a little bit this is what I have until now.
Code:
public static String books(String autor, String titel, String preis) {
HashSet<String> book = new HashSet<>(Arrays.asList(autor, titel, preis));
for (int i = 0; i <= 5; i++) {
book.add(titel);
Comparable<String> anotherBook = new Comparable<String>() {
@Override
public int compareTo(String o) {
return 0;
}
};
TreeSet<String> output = new TreeSet<>(Arrays.asList(preis, titel, autor));
}
System.out.println(book);
return null;
}