In JavaScript
, you can declare all the keys and value combinations for a JSON
object in one go as follows...
var myJSON = {
'key1' : 'value 1',
'key2' : 'value 2',
'key3' : 'value 3',
'key4' : 'value 4',
'key5' : 'value 5',
'key6' : 'value 6'
};
I was wondering whether we can do something similar in Java
for HashMaps
.
HashMap<String, String> map = new HashMap<String, String>(
"Key 1", "Value 1",
"Key 2", "Value 2",
"Key 3", "Value 3"
);
Basically, I need this as a one time read only thing as Config for the other parts of my code. I searched and tried a few solutions, but was not able to make them work. Or is there a better approach that I can do?