working with a given class like this
class MyClass{
private String name;
MyClass(String name){this.name=name;}
public String getName(){return this.name;}
}
with a collection like this
List<MyClass>cl = Arrays.asList(
new MyClass("Mike"),
new MyClass("Luke"),
new MyClass("John"),
new MyClass("Mike"),
new MyClass("Luke")
);
i am able to have a String list of unique names
List<String>uniqueNames = cl.stream().map(a->a.getName()).distinct()
.collect(Collectors.toList());
what i want is MyClass list instead of a String list but i don't get how to return MyClass instead of the String from .getName() inside the stream
edit: that "duplicate" just explains the distinct function, i put .distinct() just as an example, i may want all the classes with names that begins with "M" for example. I want to know the best way to return a class object when i check the predicate with .map() or something equivalent instead of using a filter.