public class Test {private static Map<object, object> Sourcemap = new Hashmap<object, object> ();private static Map<object, object> Targetmap = new Hashmap<object, object> ();static {Sourcemap.put ("source", "s");Targetmap.put ("target", "T");}public static void Main (string[] args) {For (Entry<object, object> map:sourceMap.entrySet ()) {Object Sourcekey = Map.getkey ();Object Sourcevalue = Map.getvalue ();Object Targetkey = Test.getconventkey (Targetmap);Object Targetvalue = Test.getconventvalue (Targetmap);Sourcemap.remove (Sourcekey);Targetmap.remove (Targetkey);Sourcemap.put (Targetkey, Targetvalue);Targetmap.put (Sourcekey, Sourcevalue);For (Entry<object, object> map1:sourceMap.entrySet ()) {Object sourceKey1 = Map1.getkey ();Object sourceValue1 = Map1.getvalue ();System.out.println ("sourcekey1=" + sourceKey1+ ", sourcevalue1=" + sourceValue1);}This print error is being analyzed.System.out.println ("sourcekey=" + Sourcekey + ", sourcevalue="+ Sourcevalue + "\ntargetkey=" + Targetkey+ ", targatvalue=" + targetvalue);}}private static Object Getconventkey (Map<object, object> targetmap) {Object key = null;For (Entry<object, object> map:targetmap.entrySet ()) {Key = Map.getkey ();}Return key;}private static Object Getconventvalue (Map<object, object> targetmap) {Object value = null;For (Entry<object, object> map:targetmap.entrySet ()) {Value = Map.getvalue ();}return value;}}
Replace the Key-value in the two map