Why does .clear()
destroy my object list even after being put in a hashmap as opposed to just making a new instance of that object?
Variable Declarions:
List<Pricing_Data> toAdd = new ArrayList<Pricing_Data>();
HashMap<String, List<Pricing_Data>> pricingMap_twelve = new HashMap<String, List<Pricing_Data>>();
Example working as expected:
pricingMap_twelve.put(pricing.get(y).getName(), toAdd);
toAdd = new ArrayList<Pricing_Data>();
Example unexepected destruction of data in hashmap after being added to said hashmap:
pricingMap_twelve.put(pricing.get(y).getName(), toAdd);
toAdd.clear();
I'm guessing this has to do with a similar issue where I ran into when first messing around with calendars where the data isn't actually 'put' into the object but is instead a pointer to the original?