Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to copy one hashmap content to another hashmap [closed]

Tags:

java

hashmap

Here I have two hashmaps dataz and screen_dataz. I want to copy screen_dataz to dataz.

I am trying like this but it's not working:

Object[]  obj = new Object[5];
String[] strArray = new String[]{"Obj1","Array1","Converted1","To1","List1"};
String[] strArray1 = new String[]{"Obj2","Array2","Converted2","To2","List2"};
dataz.put(0,(Object[]) strArray);
dataz.put(1,(Object[]) strArray1);
// String dataString = (String) dataz;
System.out.println(dataz);


Object[]  obj1= new Object[5];
String[] strArray2 = new String[]{"Obj3","Array3","Converted3","To3","List3"};
String[] strArray3 = new String[]{"Obj4","Array4","Converted4","To4","List4"};
screen_dataz.put(0,(Object[]) strArray2);
screen_dataz.put(1,(Object[]) strArray3);
System.out.println("copying screen dataz to dataz");
dataz.putAll(screen_dataz);
like image 776
user Avatar asked Nov 28 '22 01:11

user


1 Answers

Make use of constructor and Shallow it .

dataz = new HashMap<Key,val>(screen_dataz);
like image 179
Suresh Atta Avatar answered Dec 04 '22 20:12

Suresh Atta