What use is Java 6 interface MultivaluedMap?
The interface does not belong to "Java", meaning that the interface is not a part of the core libraries. It is a part of the javax.ws.rs
hierarchy which is part of the JAX-RS specification. It is used by frameworks implementing the specification such as Jersey. It is used whenever maps should refer to not only a single value but to any number of values. An example for the use would be for example the storage of a request header where you one might want to add several values per key. Or even no keys in some cases where it is easier to handle an empty list compared to a null
value.
Take this HTTP-header for example:
Accept-Encoding: compress;q=0.5, gzip;q=1.0
You would model this by
MultivaluedMap<String, String> map = ...
map.add("Accept-Encoding", "compress;q=0.5");
map.add("Accept-Encoding", "gzip;q=1.0");
internally in Jersey. This type of multiple value storage is a common problem in Java that is addressed by other implementors of maps such as Guava.
This is basically what the javadoc says:
A map of key-values pairs. Each key can have zero or more values.
Its a map of key-values pairs. Each key can have zero or multiple values
public interface MultivaluedMap<K,V> extends java.util.Map<K,java.util.List<V>>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With