java - How to put in map according to array? -
i've got 2 maps , 1 array. first map empty , second full of data. array includes string keys. want put data second map 1st if there equals keys in array.
example:
1st map: empty
2nd map(key,value): foo,1; bar,2; java,3; pojo,4; tom,5; jerry,6;
array(string): foo,java,pojo;
so need put (foo,1;java,3;pojo,4;) in 1st map.
public static void main(string[] args) throws ioexception { hashmap<string, integer> map1= new hashmap<string, integer>(); hashmap<string, integer> map2= new hashmap<string, integer>(); map2.put("foo", 1); map2.put("bar", 2); map2.put("java", 3); map2.put("pojo", 4); map2.put("tom", 5); map2.put("jerry", 6); string[] arr={"foo","java","pojo"}; (string arritem : arr) { map1.put(arritem, map2.get(arritem)); system.out.println(arritem); system.out.println(map2.get(arritem)); } }
vote / accept answer if solves query
Comments
Post a Comment