This does need iteration unfortunately. But it’s pretty trivial with Java 8 streams:
mapCopy = map.entrySet().stream()
.collect(Collectors.toMap(e -> e.getKey(), e -> List.copyOf(e.getValue())))
More Related Contents:
- Copying a HashMap in Java
- Get List<K> from HashMap<K, V> where V is instance of I [closed]
- Java 8 Streams hashmap
- Make copy of an array
- How do I do a deep copy of a 2d array in Java?
- How does a Java HashMap handle different objects with the same hash code?
- Which Java Collection should I use?
- java.lang.OutOfMemoryError: GC overhead limit exceeded [duplicate]
- is the Java HashMap keySet() iteration order consistent?
- Is it safe to get values from a java.util.HashMap from multiple threads (no modification)?
- “Cannot create generic array of ..” – how to create an Array of Map?
- Best way to create a hashmap of arraylist
- Remove Elements from a HashSet while Iterating [duplicate]
- How to make HashMap work with Arrays as key?
- ArrayList as key in HashMap
- What is the time complexity of HashMap.containsKey() in java?
- How to prove that HashMap in java is not thread-safe
- What exactly is bucket in hashmap?
- Changing HashMap keys during iteration
- When and how does HashMap convert the bucket from linked list to Red Black Trees? [duplicate]
- Loading a map using Properties class
- How can I sort Map values by key in Java?
- Accessing the last entry in a Map
- How to calculate HashMap memory usage in Java?
- Shortcut for adding to List in a HashMap
- Why Hashtable does not allow null keys or values?
- How does ConcurrentHashMap work internally?
- Why are immutable objects in hashmaps so effective?
- How to convert a string to a HashMap? [duplicate]
- Explain the timing causing HashMap.put() to execute an infinite loop