Clone a map in Java
Description
The following code shows how to clone a map.
Example
/* www . jav a 2 s. c o m*/
import java.util.HashMap;
import java.util.Map;
public class Main {
/**
* Clones a map.
*
* @param source the source map
* @return the clone of the source map
*/
public static Map copy(Map source) {
if(source == null) {
return null;
}
Map result = new HashMap();
result.putAll(source);
return result;
}
}