Reputation: 107
I am looking a way yo storage array like this:
array['name'] or array.add('name','value').
arrayList doesnt work like that. What's the best way to storage values like that?
Upvotes: 0
Views: 84
Reputation: 26502
Use a Map
. A HashMap
is a good choice:
Map<String, String> map = new HashMap<String, String>();
// to add name/value pairs - like your array.add('name','value')
map.put("name", "value");
// to retrieve values - like your array['name']
map.get("name");
Upvotes: 6