Using Java 8 streams how do I convert Map<String, List<Something>> to Map<String, Integer>?

Nfff3

So, I want to make a new map from the old one. In the new Map<String, Integer> the String key denotes the same key as in the first map and the Integer value denotes the size of the corresponding List<Something>. I want to make the transformation using Java 8 streams. I tried something like, but it gives me errors.

Map<String, List<Something>> map1=.....
Map<String, Integer> map2;
map2=map1.entrySet().stream().collect(Collectors.toMap(p-> p.getKey(), p->getValue().size()));
djm.im

It missing p before getValue()

map2 = map1.entrySet().stream()
        .collect(Collectors.toMap(p -> p.getKey(), p -> p.getValue().size()));

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Convert Map<String,List<Person>> to Map<String,List<Employee>>, using Java 8 streams. I did this but how do this without for loop

Using Java 8 streams, how to transform Map<String, Map<String, List<Person>>> to Map<Integer, Map<String, Integer>>?

Java 8 stream: how to Convert Map<String, List<Integer>> to Map<Integer, List<String>> using groupingBy(.)

Convert List<Map<String, Object>> to Map<String, List<Map<String, Object>>> using Java 8 streams API

convert list of object into a map of <String,Map<String,Integer>> java8 streams

How do I convert a List<Employee> to Map<Employee, List<String>> using java8?

How do you convert Map<String, Person> to Map<String, Integer> in java streams inside collect?

Java order Map<String, Integer> by List<String> using streams

Java 8 streams, convert List of object to Map<String, Set<String>>

How to convert Map<String, List<String>> to Set<String> using streams?

Transform a List<Object> to a Map<String,Integer> such that the String is not a duplicate value using Java 8 Streams

Create Map<String, List<Integer>> from String[][] using java 8 streams

Convert a Collection to Map<String,Collection<String>> using java 8 streams

convert List<E> to Map<String, List<String>> using java 8 streams

Convert Map<Integer, List<Object>> to Map<Integer, Map<String, Map<LocalDate, Integer>>> using Java stream API

Java-8 Streams: Convert Map<String, List<List<DataType>>> to Map<String, List<DataType>>

Java-8 Streams: Convert List<{String,List<String>}> to Map<String, List<String>>

Java 8: How to convert List<String> to Map<String,List<String>>?

Create a map of String and sorted list using Java 8 streams API

How to convert List<Object[]> to Map<String,BigInteger> with Streams & Lambda Java8

How do i convert a String to a List<Map<String,String>>

Ordering Map<String, Integer> by List<String> using streams

Java 8 stream to Map<Integer, List<String>>

How do I iterate through a map that has value, Map<String,Integer> declared as Map<String,Map<String,Integer>>using Expression Language ?

Can I convert a Map<String, List<Integer>> into a MultiValueMap<String, Integer>

How to convert List<AnyClassObject> to List<Map<String, String>> using Stream in java 8?

How can I create a map of type Map<Integer, Map<String, Integer>> in Java 8?

Java 8 Convert List of List of String to Map

How to Convert a Map<String, List<String>> to Map<String, String> in java 8