Answers for "java convert list to map"

0

java map string to list

Map<String, List<String>> myMaps = new HashMap<String, List<String>>();
    for (DataObject item : myList) {
        if (!myMaps.containsKey(item.getKey())) {
            myMaps.put(item.getKey(), new ArrayList<String>());
        }
        myMaps.get(item.getKey()).add(item.getValue());
    }
Posted by: Guest on May-20-2020
0

list to map of list java 8

Map<String,Set<String>> map =  list.stream().
           collect(Collectors.groupingBy(
                    Student::getName,
                    Collectors.mapping(e->getNum(e.getAddr()), Collectors.toSet())
                ));

   System.out.println("Map : "+map);
Posted by: Guest on March-08-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language