I am sroring a class object with variable qty value 10 in HashMap.
Later i retrived the object and made changes(set qty 20).
This value is updated in Object stored in Hashmap?
Plaese exaplin this.
import java.util.*;
public class MapTest
{ public static void main(
String args[])
{ HashMap hMap=new HashMap();
DobCheck obj=new DobCheck();
obj.setQty(10);
String temp="check";
hMap.put(temp,obj);
DobCheck obj1=(DobCheck)hMap.get("check");
System.out.println("value is "+obj1.getQty()); // value is 10
obj1.setQty(20);//modifying the value of retrived object
DobCheck obj2=(DobCheck)hMap.get("check"); //fetching original
System.out.println("value is "+obj2.getQty());///value is 20?
}
}
import java.io.Serializable;
public class DobCheck implements Serializable
{ private int qty=0;
public void setQty(int qty)
{ this.qty=qty;
}
public int getQty()
{ return this.qty;
}
}