Spring – MultiValueMap and LinkedMultiValueMap

MultiValueMap is common object type in Spring Utils source code.

Here is an example of how to use it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
MultiValueMap<String, String> multiValueMaps = new LinkedMultiValueMap<String, String>();
multiValueMaps.add("Tom", "Book");
multiValueMaps.add("Tom", "Pen");
 
multiValueMaps.add("ABC", "Company");
multiValueMaps.add("ABC", "WebSite");
 
for(String key: multiValueMaps.keySet()) {
	List<String> value = multiValueMaps.get(key);
	System.out.print(key + "\t");
	for(String s: value) {
		System.out.print(s + "\t");
	}
	System.out.println();
}