I have one model called Person with properties
name
image
age
amount
and I have a singleton hashmap Hashmap<String,Person> globalPersonList
which contains list of person objects.
I am trying to retrieve one single object from my hashmap like
Person existingPerson = globalPersonList.get("key");
I want to create a new Person
instance and initiallize with existingPerson
properties like
Person person = new Person();
person = globalPersonList.get("key");
Now I want to set amount field to this person object. I tried like
newPerson.setAmount(100);
but it shouldn't affect globalPersonList
. I want amount value only in my newPerson object. But right now this is set in globalPersonList
also. after setting amount if I try to
globalPersonList.get("key").getAmount()
it is giving the amount that I set. Is it using the reference to new object? I want a seperate copy of Person object so that it won't affect main hashmap.