KyleKW KyleKW - 2 months ago 11
Java Question

Setting and Getting with Java Hashmaps

I'd like to create a HashMap with two String values. The first string value is of some "Mode" and the second string value is of some "State" for example:

"TRACK" mode is "DISABLED"

I would like to create a HashMap with multiple defined modes, with a "State" associated with each that changes from "ENABLED" or "DISABLED". This is what I have so far:

public class SystemModeStatus{

private Map<String String> map = new HashMap<String,String>(){
put("MODE_A", "STATE");
put("MODE_B", "STATE");
put("MODE_C", "STATE");

public SystemModeStatus(Map<String, String> m){ = m;

public Map<String, String> getMap(){

Now what I would like to do is retrieve/set the "State" of each "Mode". However I can't seem to find the proper syntax.. am I approaching this correctly? Is there somethind I'm doing wrong that is complicating my process?

Thank you.


Firstly you should probably remove the getMap() method as you want to expose as few methods as possible on the internal map.

Then you can add methods to update the values in your map:

public void set(String mode, String status) {, status);

public String getStatus(String mode) {

More info here: