I am new to Java programming. I created a hash map that contains my key value pairs in order to use the value corresponding to the corresponding key when replacing user input.
i.e.
HashMap<String,String> questionKey = new HashMap<>(); for (item : itemSet()) { questionKey.put(String.valueOf(item.getOrder()+1), item.getKey()); } String list = commandObject.getObjectItem().getList(); if (list.contains("q")){ list.replaceAll("q01", questionKey.get("1")); commandObject.getObjectItem().setList(list); }
I use this in evaluating a formula
Note. Users are given a specific way to enter a specific formula (value1 + value2 + value3)
I take this value (value1 value2 value3) and convert it to (value1key value2key value3key)
Update:
The question, as I understand it, is now better to help better understand how to use a hash map to evaluate user input. More clear question:
What would be the best approach to evaluate ie
User input = "var1 + var2"
Expected value: valueOf (var1) + valueOf (var2)
?
source share