import java.util.*;
import java.util.stream.*;
import static java.util.stream.Collectors.*;

class Person {
	final String name, surname;
	public Person(String n, String s){
		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()))
            );
        System.out.println(map);
	}
}