java stream group by multiple field names

java stream group by multiple field names
refe‮‬r to:lautturi.com
/**
 * @author lautturi.com 
 * Java example: group by multiple field names in java 
 */

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

class Person{
	String name;
	int age;
	
	public Person(String string, int i) {
		name = string;
		age = i;
	}

	public String getName() {
		return name;
	}
	public int getAge() {
		return age;
	}
}

public class Lautturi {
	public static void main(String[] args){
		
		Stream<Person> persons = Stream.of(
				new Person("Alan",13),
				new Person("Bob",25),
				new Person("James",22),
				new Person("Tom",22),
				new Person("Alan",23),
				new Person("Bob",27)
	    );
				
		Map<String, Map<Integer, List<Person>>> map =  
				persons.collect(Collectors.groupingBy(Person::getName,
			        Collectors.groupingBy(Person::getAge)));
		
		System.out.println(map.get("Tom").get(22));
		System.out.println(map.get("Alan"));
		System.out.println(map.get("Alan").get(23));
	}
}

output:

[hello.Person@87aac27]
{23=[hello.Person@3e3abc88], 13=[hello.Person@6ce253f1]}
[hello.Person@3e3abc88]
Created Time:2017-09-30 16:59:29  Author:lautturi