Tag Archives: Apache

Apache Commons Collection – MultiValuedMap

Apache Commons Collection is a library of useful data structures, collections, and algorithms in Java. MultiValuedMap is one of the data structures present in the Apache Commons Collection. MultiValuedMap is a Map that allows multiple values for a single key. It is a useful implementation of a one-to-many relationship. You can add multiple values to the same key, and the key-value pairs are stored in the order in which they are added.

Here’s an example Java code of using MultiValuedMap:

import org.apache.commons.collections4.MultiValuedMap;
import org.apache.commons.collections4.multimap.ArrayListValuedHashMap;
public class MultiValuedMapDemo {
    public static void main(String[] args) {
        MultiValuedMap<String, String> multiValuedMap = new ArrayListValuedHashMap<>();
        multiValuedMap.put("Key1", "Value1");
        multiValuedMap.put("Key1", "Value2");
        multiValuedMap.put("Key2", "Value3");
        System.out.println(multiValuedMap.get("Key1"));
    }
}

Continue reading Apache Commons Collection – MultiValuedMap