I have a List<Employee>
e which I want to convert into
Map<String, Map<String,Emp>>
where the outer string should be "Name" and the inner string should be "Domain".
Name Id Domain
e(0) - Emp1, 1, Insurance
e(1) - Emp1, 2, Sales
e(2) - Emp2, 3, Sales
e(3) - Emp4, 4, Marketing
I am tried the following-
e.stream().collect(Collectors.groupingBy(
Employee::getName,
toMap(Employee::getDomain,Emp)));
So the expected output map should look like
<Emp1>
<Insurance, e(0)>
<Sales, e(1)>
<Emp2>
<Sales, e(2)>
<Emp4>
<Marketing, e(3)>
But I get only unique values, actual output-
<Emp1>
<Insurance, e(0)>
<Emp2>
<Sales, e(2)>
<Emp4>
<Marketing, e(3)>
Can someone tell the best way to do it?