You can just use a normal Map<String, List<String>> type, for example:
String key = "keyValue";
String value1 = "value1";
String value2 = "value2";
String value3 = "value3";
Map<String, List<String>> requestAttrbs1 = new HashMap<String, List<String>>();
if (!requestAttrbs1.containsKey(key)) {
requestAttrbs1.put(key, new ArrayList<String>());
}
requestAttrbs1.get(key).add(value1);
requestAttrbs1.get(key).add(value2);
requestAttrbs1.get(key).add(value3);
requestAttrbs1.get(key).remove(value2);
for (String value : requestAttrbs1.get(key)) {
System.out.println(value);
}
Alternatively, if you can use libraries you might want to look at the MultiValueMap in Commons Collections:
MultiValueMap<String, String> requestAttrbs2 = new MultiValueMap<String, String>();
requestAttrbs2.put(key, value1);
requestAttrbs2.put(key, value2);
requestAttrbs2.put(key, value3);
requestAttrbs2.removeMapping(key, value2);
for (String value : requestAttrbs2.getCollection(key)) {
System.out.println(value);
}
Both code snippets will print out:
value1
value3
As you can see the MultiValueMap version is slightly shorter, saving you the trouble of checking whether the key already exists and explicitly getting the list out yourself.
Map<Integer,Set<Integer>where123is key and[12,13,14]is value