Package org.springframework.util

# Interface MultiValueMap<K,V>

Type Parameters:
  `K` - the key type
  `V` - the value element type

All Superinterfaces:
  `Map<K,List<V>>`

All Known Implementing Classes:
  `LinkedMultiValueMap`, `MultiValueMapAdapter`

public interface MultiValueMap<K,V> extends Map<K,List<V>>
Extension of the `Map` interface that stores multiple values.

Since:
  3.0
Author:
  Arjen Poutsma

## Nested Class Summary

## Nested classes/interfaces inherited from interface java.util.Map

`Map.Entry<K extends Object,V extends Object>`

## Method Summary

Modifier and Type
Method
Description
`void`
`add(K key, V value)`
Add the given single value to the current list of values for the given key.
`void`
`addAll(K key, List<? extends V> values)`
Add all the values of the given list to the current list of values for the given key.
`void`
`addAll(MultiValueMap<K,V> values)`
Add all the values of the given `MultiValueMap` to the current values.
`default void`
`addIfAbsent(K key, V value)`
`Add` the given value, only when the map does not `contain` the given key.
`default Map<K,V>`
`asSingleValueMap()`
Return this map as a `Map` with the first values contained in this `MultiValueMap`.
`static <K, V> MultiValueMap<K,V>`
`fromMultiValue(Map<K,List<V>> map)`
Return a `MultiValueMap<K, V>` that adapts the given multi-value `Map<K, List<V>>`.
`static <K, V> MultiValueMap<K,V>`
`fromSingleValue(Map<K,V> map)`
Return a `MultiValueMap<K, V>` that adapts the given single-value `Map<K, V>`.
`V`
`getFirst(K key)`
Return the first value for the given key.
`void`
`set(K key, V value)`
Set the given single value under the given key.
`void`
`setAll(Map<K,V> values)`
Set the given values under.
`Map<K,V>`
`toSingleValueMap()`
Return a `Map` with the first values contained in this `MultiValueMap`.

### Methods inherited from interface java.util.Map

`clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values`

## Method Details

### getFirst

@Nullable V getFirst(K key)
Return the first value for the given key.

Parameters:
  `key` - the key
Returns:
  the first value for the specified key, or `null` if none

### add

void add(K key, @Nullable V value)
Add the given single value to the current list of values for the given key.

Parameters:
  `key` - the key
  `value` - the value to be added

### addAll

void addAll(K key, List<? extends V> values)
Add all the values of the given list to the current list of values for the given key.

Parameters:
  `key` - they key
  `values` - the values to be added
Since:
  5.0

### addAll

void addAll(MultiValueMap<K,V> values)
Add all the values of the given `MultiValueMap` to the current values.

Parameters:
  `values` - the values to be added
Since:
  5.0

### addIfAbsent

default void addIfAbsent(K key, @Nullable V value)
`Add` the given value, only when the map does not `contain` the given key.

Parameters:
  `key` - the key
  `value` - the value to be added
Since:
  5.2

### set

void set(K key, @Nullable V value)
Set the given single value under the given key.

Parameters:
  `key` - the key
  `value` - the value to set

### setAll

void setAll(Map<K,V> values)
Set the given values under.

Parameters:
  `values` - the values.

### toSingleValueMap

Map<K,V> toSingleValueMap()
Return a `Map` with the first values contained in this `MultiValueMap`. The difference between this method and `asSingleValueMap()` is that this method returns a copy of the entries of this map, whereas the latter returns a view.

Returns:
  a single value representation of this map

### asSingleValueMap

default Map<K,V> asSingleValueMap()
Return this map as a `Map` with the first values contained in this `MultiValueMap`.

The difference between this method and `toSingleValueMap()` is that this method returns a view of the entries of this map, whereas the latter returns a copy.

Returns:
  a single value representation of this map
Since:
  6.2

### fromSingleValue

static <K, V> MultiValueMap<K,V> fromSingleValue(Map<K,V> map)
Return a `MultiValueMap<K, V>` that adapts the given single-value `Map<K, V>`.

The returned map cannot map multiple values to the same key, and doing so results in an `UnsupportedOperationException`. Use `fromMultiValue(Map)` to support multiple values.

Type Parameters:
  `K` - the key type
  `V` - the value element type
Parameters:
  `map` - the map to be adapted
Returns:
  a multi-value-map that delegates to `map`
Since:
  6.2
See Also:
  - `fromMultiValue(Map)`

### fromMultiValue

static <K, V> MultiValueMap<K,V> fromMultiValue(Map<K,List<V>> map)
Return a `MultiValueMap<K, V>` that adapts the given multi-value `Map<K, List<V>>`.

Type Parameters:
  `K` - the key type
  `V` - the value element type
Parameters:
  `map` - the map to be adapted
Returns:
  a multi-value-map that delegates to `map`
Since:
  6.2
See Also:
  - `fromSingleValue(Map)`