package Algorithmus;

import java.util.*;

public class Person {
	 String name;
	    int alter;

	    Person(String name, int alter) {
	        this.name = name;
	        this.alter = alter;
	    }
    
	public static void main(String[] args) {
	
		Person[] arr = { new Person("Anna", 25),new Person("Ben", 30),  new Person("Clara", 25),new Person("Daniel", 30)};
		
		Map<Integer, List<String>> merker = new HashMap<>();
		
		for (int i = 0; i < arr.length; i++) {
			int alter = arr[i].alter;
			if (!merker.containsKey(alter)) 
				merker.put(alter, new ArrayList<>());
	
			merker.get(alter).add(arr[i].name);
		}
		System.out.println(merker.toString());
	}

}
