Map (Java SE 25 & JDK 25)
- Type Parameters:
K- the type of keys maintained by this mapV- the type of mapped values
- All Known Subinterfaces:
Bindings, ConcurrentMap<K,V>, ConcurrentNavigableMap<K, V>, NavigableMap<K, V>, SequencedMap<K, V>, SortedMap<K, V>
- All Known Implementing Classes:
AbstractMap, Attributes, AuthProvider, ConcurrentHashMap, ConcurrentSkipListMap, EnumMap, HashMap, Hashtable, Headers, IdentityHashMap, LinkedHashMap, PrinterStateReasons, Properties, Provider, RenderingHints, SimpleBindings, TabularDataSupport, TreeMap, UIDefaults, WeakHashMap
-
Nested Class Summary
Nested Classes
static interfaceA map entry (key-value pair).
-
Method Summary
voidclear()Removes all of the mappings from this map (optional operation).
default Vcompute(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) Attempts to compute a mapping for the specified key and its current mapped value, or
nullif there is no current mapping (optional operation).default VcomputeIfAbsent(K key, Function<? super K, ? extends V> mappingFunction) If the specified key is not already associated with a value (or is mapped to
null), attempts to compute its value using the given mapping function and enters it into this map unlessnull(optional operation).default VcomputeIfPresent(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) If the value for the specified key is present and non-null, attempts to compute a new mapping given the key and its current mapped value (optional operation).
booleanReturns
trueif this map contains a mapping for the specified key.booleanReturns
trueif this map maps one or more keys to the specified value.static <K,V> Map <K, V> copyOf(Map<? extends K, ? extends V> map) Returns an unmodifiable Map containing the entries of the given Map.
entry(K k, V v) Returns an unmodifiable
Map.Entrycontaining the given key and value.entrySet()Returns a
Setview of the mappings contained in this map.booleanCompares the specified object with this map for equality.
default voidPerforms the given action for each entry in this map until all entries have been processed or the action throws an exception.
Returns the value to which the specified key is mapped, or
nullif this map contains no mapping for the key.default VgetOrDefault(Object key, V defaultValue) Returns the value to which the specified key is mapped, or
defaultValueif this map contains no mapping for the key.inthashCode()Returns the hash code value for this map.
booleanisEmpty()Returns
trueif this map contains no key-value mappings.keySet()Returns a
Setview of the keys contained in this map.default Vmerge(K key, V value, BiFunction<? super V, ? super V, ? extends V> remappingFunction) If the specified key is not already associated with a value or is associated with null, associates it with the given non-null value (optional operation).
static <K,V> Map <K, V> of()Returns an unmodifiable map containing zero mappings.
static <K,V> Map <K, V> of(K k1, V v1) Returns an unmodifiable map containing a single mapping.
static <K,V> Map <K, V> of(K k1, V v1, K k2, V v2) Returns an unmodifiable map containing two mappings.
static <K,V> Map <K, V> of(K k1, V v1, K k2, V v2, K k3, V v3) Returns an unmodifiable map containing three mappings.
static <K,V> Map <K, V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4) Returns an unmodifiable map containing four mappings.
static <K,V> Map <K, V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5) Returns an unmodifiable map containing five mappings.
static <K,V> Map <K, V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6) Returns an unmodifiable map containing six mappings.
static <K,V> Map <K, V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7) Returns an unmodifiable map containing seven mappings.
static <K,V> Map <K, V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8) Returns an unmodifiable map containing eight mappings.
static <K,V> Map <K, V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8, K k9, V v9) Returns an unmodifiable map containing nine mappings.
static <K,V> Map <K, V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8, K k9, V v9, K k10, V v10) Returns an unmodifiable map containing ten mappings.
static <K,V> Map <K, V> ofEntries(Map.Entry<? extends K, ? extends V>... entries) Returns an unmodifiable map containing keys and values extracted from the given entries.
Associates the specified value with the specified key in this map (optional operation).
voidputAll(Map<? extends K, ? extends V> m) Copies all of the mappings from the specified map to this map (optional operation).
default VputIfAbsent(K key, V value) If the specified key is not already associated with a value (or is mapped to
null) associates it with the given value and returnsnull, else returns the current value (optional operation).Removes the mapping for a key from this map if it is present (optional operation).
default booleanRemoves the entry for the specified key only if it is currently mapped to the specified value (optional operation).
default VReplaces the entry for the specified key only if it is currently mapped to some value (optional operation).
default booleanreplace(K key, V oldValue, V newValue) Replaces the entry for the specified key only if currently mapped to the specified value (optional operation).
default voidreplaceAll(BiFunction<? super K, ? super V, ? extends V> function) Replaces each entry's value with the result of invoking the given function on that entry until all entries have been processed or the function throws an exception (optional operation).
intsize()Returns the number of key-value mappings in this map.
values()Returns a
Collectionview of the values contained in this map.
-
Method Details
-
size
-
isEmpty
-
containsKey
-
containsValue
-
get
-
put
-
remove
-
putAll
-
clear
-
keySet
-
values
-
entrySet
-
equals
-
hashCode
-
getOrDefault
-
forEach
-
replaceAll
-
putIfAbsent
-
remove
-
replace
-
replace
-
computeIfAbsent
-
computeIfPresent
-
compute
-
merge
-
of
-
of
-
of
-
of
-
of
-
of
-
of
-
of
-
of
-
of
-
of
-
ofEntries
-
entry
-
copyOf
-