I have the Person class:
import java.util.*; public class Person { private String name; Map<String,Integer> Skills=new HashMap<>(); // skill name(String) and level(int) public String getName(){ return this.name; } public Map<String,Integer> getSkills(){ return this.Skills; } } And the App class:
import java.util.*; import java.util.Map.Entry; import static java.util.stream.Collectors.*; import static java.util.Comparator.*; public class App { private List<Person> people=new ArrayList<>(); // the people in the company public Map<String,Set<String>> PeoplePerSkill(){ return this.people.stream().collect(groupingBy(p-> p.getSkills().keySet() //<-get //^problem here ,mapping(Person::getName,toSet()))); } } In the App class the PeoplePerSkill method need to return the Set of people names per skill. It means a skill could be owned by many people.
I stuck with the groupingBy(p->p..........., ) I just can't get the String of skill's name, I tried so many ways but things get way stranger :(.
By the way, currently my code returns Map<Object, Set<String>>