import java.util.*;
import java.util.stream.*;
import static java.util.stream.Collectors.*;
class Person {
this.name = n;
this.surname = s;
}
public String getName
(){ return name
; } public String getSurname
(){ return surname
; } }
class Ideone {
public static void main
(String[] args
) { List
<Person
> people
= Arrays.
asList( new Person("Sam", "Rossi"),
new Person("Sam", "Verdi"),
new Person("John", "Bianchi"),
new Person("John", "Rossi"),
new Person("John", "Verdi")
);
Map
<String, List
<String
>> map
= people.
stream() .collect(
// function mapping input elements to keys
groupingBy(Person::getName,
// function mapping input elements to values,
// how to store values
mapping(Person::getSurname, toList()))
);
}
}
aW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS51dGlsLnN0cmVhbS4qOwppbXBvcnQgc3RhdGljIGphdmEudXRpbC5zdHJlYW0uQ29sbGVjdG9ycy4qOwoKY2xhc3MgUGVyc29uIHsKCWZpbmFsIFN0cmluZyBuYW1lLCBzdXJuYW1lOwoJcHVibGljIFBlcnNvbihTdHJpbmcgbiwgU3RyaW5nIHMpewoJCXRoaXMubmFtZSA9IG47CgkJdGhpcy5zdXJuYW1lID0gczsKCX0KCXB1YmxpYyBTdHJpbmcgZ2V0TmFtZSgpeyByZXR1cm4gbmFtZTsgfQoJcHVibGljIFN0cmluZyBnZXRTdXJuYW1lKCl7IHJldHVybiBzdXJuYW1lOyB9Cn0KCmNsYXNzIElkZW9uZSB7CgkKCXB1YmxpYyBzdGF0aWMgdm9pZCBtYWluKFN0cmluZ1tdIGFyZ3MpIHsKCSAgICBMaXN0PFBlcnNvbj4gcGVvcGxlID0gQXJyYXlzLmFzTGlzdCgKCQkgICAgbmV3IFBlcnNvbigiU2FtIiwgIlJvc3NpIiksCgkJICAgIG5ldyBQZXJzb24oIlNhbSIsICJWZXJkaSIpLAoJCSAgICBuZXcgUGVyc29uKCJKb2huIiwgIkJpYW5jaGkiKSwKCQkgICAgbmV3IFBlcnNvbigiSm9obiIsICJSb3NzaSIpLAoJCSAgICBuZXcgUGVyc29uKCJKb2huIiwgIlZlcmRpI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