#Overwrite existing initialized HashMap with a new one?
7 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @light oyster! Please use
/closeor theClose Postbutton above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
you need to reference the HashMap from an initialised object
So lets say I have a class called Users which holds the HashMap userInfo:
class Users {
public HashMap<String,String> userInfo = new HashMap<>();
//rest of the code
}
If I want to access this field i need to create an instance of the class Users. I can then access the userInfo field and update the HashMap or override it entirely.
public static void main(String[] args) {
Users users = new Users();
HashMap<String,String> dataSet1 = new HashMap<>();
dataSet1.put("Name1","1");
dataSet1.put("Name2","2");
users.userInfo = dataSet1;
System.out.println(users.userInfo);
}
how are you accessing the field userInfo , please show me the relevant code.
no worries
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.