Create a Map from a list of objects with Stream (Java 8)

class MyClass{ private Integer identifier; //Other attributes public Integer getIdentifier(){ return this.identifier; } } List<MyClass> listOfMyClass; Map<Integer,List<MyClass>> mapOfMyCLass = listOfMyClass.stream().collect(Collectors.groupingBy(MyClass::getIdentifier));
Create a Map from a list of objects with Stream (Java 8) grouping the ones that have same identifier.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.