I want to collect an enum into a treemap and I want to have case-insensitive map. From here I see https://www.baeldung.com/java-collectors-tomap how to return a treemap
public TreeMap<String, Book> listToSortedMap(List<Book> books) {
return books.stream()
.collect(
Collectors.toMap(Book::getName, Function.identity(), (o1, o2) -> o1, TreeMap::new));
}
but the natural ordering will be case-sensitive. How can I pass a custom comparator in the above return statement? Something that gives me as below
Map<String, Integer> treeMap = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);