Java HashMap clone
import java.util.HashMap; public class Main { public static void main(String a[]) { HashMap<Integer, String> hashMap = new HashMap<>(); HashMap<Integer, String> hashMap1 = new HashMap<>(); hashMap.put(1, "One"); hashMap.put(2, "Two"); hashMap.put(3, "Three"); System.out.println("Original HashMap : " + hashMap); hashMap1 = (HashMap<Integer, String>) hashMap.clone(); System.out.println("Copied HashMap : " + hashMap1); hashMap1.put(1, "new value"); System.out.println("Copied HashMap : " + hashMap1); }//from ww w . j av a2s . c o m }