Dear all,
I have declared following two hashmap.public static HashMap<Integer,String[]> m1 = new HashMap<Integer,String[]>();
public static HashMap<Integer,String[]> temp = new HashMap<Integer,String[]>();
At starting point of my execution both map will contain key from 1 to 20 and mapped value with it.
Means key value pair are same in both map.
After some processing i modify value in temp map and do operation on it.
for(int r = 0;r<q;r++)
{
Set s = temp.keySet();
Iterator it1 = s.iterator();
StringBuilder sb = null;
String[] a1 = null;
while(it1.hasNext())
{
a1 = temp.get((Integer)it1.next());
System.out.println("\n /////////////////////////////////////////////////////////////////////////");
if(len[r]>2)
{
sb = new StringBuilder(a1[loc[r]]);
rep = a1[loc[r]].length()-1;
//System.out.println("rep = "+rep);
sb.setCharAt(rep,'*');
//sb.insert(rep, "*");
a1[loc[r]]=sb.toString();
//System.out.println("updated temp = "+temp.containsValue(a1)+" updated m1= "+m1.containsValue(a1));
}
}
System.out.println("\n--------------- Map - temp ------------------------------------------");
for(Map.Entry<Integer, String[]> mapEntry2 : temp.entrySet())
{
Integer key3 = new Integer((Integer)mapEntry2.getKey());
System.out.print("\nvalue of key3 = "+key3);
String aa5[] = m1.get(key3);
if(temp.containsKey(key3))
temp.put(key3, aa5);
}
}
but it will also modify the value in map-m1, As i m not performing any operation on m1.
please tell me where the problem is.
I have also do the debug, but i can't find problem.
i just get that when i put into temp,the array location of m1 will be putted, so in next iteration the value of m1 is also modified.
please tell me what to do, for replacing only value.
Thanks