I have a map object testMap declared as HashMap<String, Test>.
Test is a simple class which contains references to an Object and to two String values.
ie,
public class Test {
private String name;
private String id;
private Object val;
public Test(Object val,String name.String id){
this.val =val;
this.id=id;
this.name = name;
}
I want to update the “name” only in the Hash map “testMap.” How can I do this?
You need to change the visibility of your
nameproperty topublicor add a setter to it:Then, to change your name, you need to
If you want to update the Map key also, then you need