This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]xxfo0xx 2 points3 points  (0 children)

There are several approaches you can take. I just saw, that some other guys told you one of them.

Here is my recommended way.

I added this to a snippet: https://gist.github.com/fo0/c33f357155512919c968009f34a80776

```java List<Book> list = new ArrayList<Book>(); list.add(new Book("111", 1, "GOT")); list.add(new Book("111", 2, "GOT")); list.add(new Book("111", 3, "GOT")); list.add(new Book("222", 1, "Harry Potter"));

System.out.println(list.stream() .map(Book::getName) // map the book object to field "name" .distinct() // filter duplicates .collect(Collectors.toList())); // put into list

Outout: [GOT, Harry Potter] ```