private static Map<String, Integer> namesToNumPurchases = new HashMap<String, Integer>() {{ put("Chris", 10); put("Bob", 5); put("David", 5); put("Sue", 12); put("Jim", 3); }}; /* Required output: 3: Jim 5: Bob, David 10: Chris 12: Sue */
Sigiloso
Map>> ret = mappy.entrySet().stream(). collect( Collectors.groupingBy( x -> x.getValue())); Map result = ret.entrySet().stream().collect ( Collectors.toMap( x -> x.getKey(), y -> y.getValue().stream().map( p -> p.getKey()).collect(Collectors.joining(",")))); System.out.println(result);