Package org.springframework.util

# Class LinkedCaseInsensitiveMap<V>

java.lang.Object
org.springframework.util.LinkedCaseInsensitiveMap<V>

Type Parameters:
  `V` - the value type

All Implemented Interfaces:
  `Serializable`, `Cloneable`, `Map<String,V>`

public class LinkedCaseInsensitiveMap<V> extends Object implements Map<String,V>, Serializable, Cloneable
`LinkedHashMap` variant that stores String keys in a case-insensitive manner, for example for key-based access in a results table.

Preserves the original order as well as the original casing of keys, while allowing for contains, get and remove calls with any case of key.

Does not support `null` keys.

Since:
  3.0
Author:
  Juergen Hoeller, Phillip Webb
See Also:
  - Serialized Form

## Nested Class Summary

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

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

## Constructor Summary

Constructors
Constructor
Description
`LinkedCaseInsensitiveMap()`
Create a new LinkedCaseInsensitiveMap that stores case-insensitive keys according to the default Locale (by default in lower case).
`LinkedCaseInsensitiveMap(int expectedSize)`
Create a new LinkedCaseInsensitiveMap that wraps a `LinkedHashMap` with an initial capacity that can accommodate the specified number of elements without any immediate resize/rehash operations to be expected, storing case-insensitive keys according to the default Locale (in lower case).
`LinkedCaseInsensitiveMap(int expectedSize, Locale locale)`
Create a new LinkedCaseInsensitiveMap that wraps a `LinkedHashMap` with an initial capacity that can accommodate the specified number of elements without any immediate resize/rehash operations to be expected, storing case-insensitive keys according to the given Locale (in lower case).
`LinkedCaseInsensitiveMap(Locale locale)`
Create a new LinkedCaseInsensitiveMap that stores case-insensitive keys according to the given Locale (in lower case).

## Method Summary

Modifier and Type
Method
Description
`void`
`clear()`
`LinkedCaseInsensitiveMap<V>`
`clone()`
`V`
`computeIfAbsent(String key, Function<? super String,? extends V> mappingFunction)`
`boolean`
`containsKey(Object key)`
`boolean`
`containsValue(Object value)`
`protected String`
`convertKey(String key)`
Convert the given key to a case-insensitive key.
`Set<Map.Entry<String,V>>`
`entrySet()`
`boolean`
`equals(Object other)`
`void`
`forEach(BiConsumer<? super String,? super V> action)`
`V`
`get(Object key)`
`Locale`
`getLocale()`
Return the locale used by this `LinkedCaseInsensitiveMap`.
`V`
`getOrDefault(Object key, V defaultValue)`
`int`
`hashCode()`
`boolean`
`isEmpty()`
`Set<String>`
`keySet()`
`V`
`put(String key, V value)`
`void`
`putAll(Map<? extends String,? extends V> map)`
`V`
`putIfAbsent(String key, V value)`
`V`
`remove(Object key)`
`protected boolean`
`removeEldestEntry(Map.Entry<String,V> eldest)`
Determine whether this map should remove the given eldest entry.
`int`
`size()`
`String`
`toString()`
`Collection<V>`
`values()`

### Methods inherited from class java.lang.Object

`finalize, getClass, notify, notifyAll, wait, wait, wait`

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

`compute, computeIfPresent, merge, remove, replace, replace, replaceAll`

## Constructor Details

### LinkedCaseInsensitiveMap

public LinkedCaseInsensitiveMap()
Create a new LinkedCaseInsensitiveMap that stores case-insensitive keys according to the default Locale (by default in lower case).

See Also:
  - `convertKey(String)`

### LinkedCaseInsensitiveMap

public LinkedCaseInsensitiveMap(@Nullable Locale locale)
Create a new LinkedCaseInsensitiveMap that stores case-insensitive keys according to the given Locale (in lower case).

Parameters:
  `locale` - the Locale to use for case-insensitive key conversion
See Also:
  - `convertKey(String)`

### LinkedCaseInsensitiveMap

public LinkedCaseInsensitiveMap(int expectedSize)
Create a new LinkedCaseInsensitiveMap that wraps a `LinkedHashMap` with an initial capacity that can accommodate the specified number of elements without any immediate resize/rehash operations to be expected, storing case-insensitive keys according to the default Locale (in lower case).

Parameters:
  `expectedSize` - the expected number of elements (with a corresponding capacity to be derived so that no resize/rehash operations are needed)
See Also:
  - `CollectionUtils.newHashMap(int)`
  - `convertKey(String)`

### LinkedCaseInsensitiveMap

public LinkedCaseInsensitiveMap(int expectedSize, @Nullable Locale locale)
Create a new LinkedCaseInsensitiveMap that wraps a `LinkedHashMap` with an initial capacity that can accommodate the specified number of elements without any immediate resize/rehash operations to be expected, storing case-insensitive keys according to the given Locale (in lower case).

Parameters:
  `expectedSize` - the expected number of elements (with a corresponding capacity to be derived so that no resize/rehash operations are needed)
  `locale` - the Locale to use for case-insensitive key conversion
See Also:
  - `CollectionUtils.newHashMap(int)`
  - `convertKey(String)`

## Method Details

### size

public int size()

Specified by:
  `size` in interface `Map<String,V>`

### isEmpty

public boolean isEmpty()

Specified by:
  `isEmpty` in interface `Map<String,V>`

### containsKey

public boolean containsKey(Object key)

Specified by:
  `containsKey` in interface `Map<String,V>`

### containsValue

public boolean containsValue(Object value)

Specified by:
  `containsValue` in interface `Map<String,V>`

### get

@Nullable public V get(Object key)

Specified by:
  `get` in interface `Map<String,V>`

### getOrDefault

@Nullable public V getOrDefault(Object key, V defaultValue)

Specified by:
  `getOrDefault` in interface `Map<String,V>`

### put

@Nullable public V put(String key, @Nullable V value)

Specified by:
  `put` in interface `Map<String,V>`

### putAll

public void putAll(Map<? extends String,? extends V> map)

Specified by:
  `putAll` in interface `Map<String,V>`

### putIfAbsent

@Nullable public V putIfAbsent(String key, @Nullable V value)

Specified by:
  `putIfAbsent` in interface `Map<String,V>`

### computeIfAbsent

@Nullable public V computeIfAbsent(String key, Function<? super String,? extends V> mappingFunction)

Specified by:
  `computeIfAbsent` in interface `Map<String,V>`

### remove

@Nullable public V remove(Object key)

Specified by:
  `remove` in interface `Map<String,V>`

### clear

public void clear()

Specified by:
  `clear` in interface `Map<String,V>`

### keySet

public Set<String> keySet()

Specified by:
  `keySet` in interface `Map<String,V>`

### values

public Collection<V> values()

Specified by:
  `values` in interface `Map<String,V>`

### entrySet

public Set<Map.Entry<String,V>> entrySet()

Specified by:
  `entrySet` in interface `Map<String,V>`

### forEach

public void forEach(BiConsumer<? super String,? super V> action)

Specified by:
  `forEach` in interface `Map<String,V>`

### clone

public LinkedCaseInsensitiveMap<V> clone()

Overrides:
  `clone` in class `Object`

### equals

public boolean equals(@Nullable Object other)

Specified by:
  `equals` in interface `Map<String,V>`
Overrides:
  `equals` in class `Object`

### hashCode

public int hashCode()

Specified by:
  `hashCode` in interface `Map<String,V>`
Overrides:
  `hashCode` in class `Object`

### toString

public String toString()

Overrides:
  `toString` in class `Object`

### getLocale

public Locale getLocale()
Return the locale used by this `LinkedCaseInsensitiveMap`. Used for case-insensitive key conversion.

Since:
  4.3.10
See Also:
  - `LinkedCaseInsensitiveMap(Locale)`
  - `convertKey(String)`

### convertKey

protected String convertKey(String key)
Convert the given key to a case-insensitive key.

The default implementation converts the key to lower-case according to this Map's Locale.

Parameters:
  `key` - the user-specified key
Returns:
  the key to use for storing
See Also:
  - `String.toLowerCase(Locale)`

### removeEldestEntry

protected boolean removeEldestEntry(Map.Entry<String,V> eldest)
Determine whether this map should remove the given eldest entry.

Parameters:
  `eldest` - the candidate entry
Returns:
  `true` for removing it, `false` for keeping it
See Also:
  - `LinkedHashMap.removeEldestEntry(java.util.Map.Entry<K, V>)`