Some List is here
List<Book> list = new ArrayList<>();
{
list.add(new Book("Core Java", 200));
list.add(new Book("Core Java", 500));
list.add(new Book("Core Java", 800));
list.add(new Book("Learning Freemarker", 150));
list.add(new Book("Learning Freemarker", 1350));
list.add(new Book("Learning Freemarker", 1250));
list.add(new Book("Spring MVC", 300));
list.add(new Book("Spring MVC", 600));
list.add(new Book("Spring MVC", 1600));
}
I want show Book list like this
Core Java", 800
Learning Freemarker", 1350
Spring MVC", 1600
each 1element
list .stream().distinct()
.sorted(Comparator.comparing(Book::bookname)
.thenComparing(Book::getPrice)).collect(Collectors.toList());
this code only sorted.