Map.put — insert or replace a value
Store a value under a key and get back the previous value. Learn when a `null` result means the key was absent and when it means the key already mapped to `null`.
CKTIS / Knowledge base
Programming syntax, operators and concepts. Find an explanation, explore an example and return to learning.
Store a value under a key and get back the previous value. Learn when a `null` result means the key was absent and when it means the key already mapped to `null`.
`Map.size()` returns the current number of key–value mappings as an `int`. Replacing the value for an existing key does not increase the size.
`Map.values()` returns a collection backed by the map. Iterate over it to sum counters without looking up their keys or dropping repeated values.
Use `find()` to search for successive regex matches, or `find(int start)` to restart the search at a specified input index.
After a successful regex match, read the whole matched text or the text captured by a specific group. Group 0 is the whole match.
`Matcher.matches()` tests a regular expression against the entire current region, not just a substring. By default, the region covers the whole input.
Find the absolute value of a number, compare floating-point values within a tolerance, and handle the smallest integer values correctly.
Math.max returns the greater of two numbers. Learn its numeric overloads and its behavior for NaN and signed zero.
`Math.min` returns the smaller of two numeric values. Use it to keep an increasing priority from going above 5.
Math.round chooses the nearest integer, breaking ties toward positive infinity. The result type depends on the overload.
MessageDigest computes one-way hashes of data. Learn how to select SHA-256, process bytes, understand the reset after digest, and compare results with isEqual.
Look up an instance method by its signature, bind the receiver into a new handle, and compare an exact call with a call that can adapt compatible types.
Find the closest stored key below or above a search key, with or without including a key that compares equal.
Use `subMap`, `headMap`, and `tailMap` to select a key range, explicitly include or exclude its endpoints, and work with the original map rather than a copy.
NoSuchFieldException is a checked exception raised when a lookup cannot find a field with the specified name. With reflection, the search scope matters: getField searches public fields, while getDeclaredField searches fields declared directly by the given type.
Get a `Number` object's value as a primitive `double`. Whether the result is exact depends on the object's actual subtype and whether the value can be represented as a `double`.
Object.equals compares object identity by default. Overriding it lets a class define value equality.
`getClass()` returns the `Class` object for an object's runtime class, regardless of the variable's declared type. It lets you test for an exact class match, but it does not reveal a generic instance's type arguments.
Object.hashCode returns an int used by hash tables. Objects equal according to equals must have matching codes; the reverse does not hold.
Compare titles safely when either may be missing, then enforce a separate non-null requirement when generating a label.
Write an object to a `byte[]` and reconstruct it from trusted bytes generated by the same program. See why default serialization omits `transient` fields.
Combine two fields into an `int` hash code, see why Java autoboxes an `int` to `Integer`, and learn how `Objects.hash` differs from `Objects.hashCode`.
In Java SE 21, `Objects.requireNonNull` returns the same reference if it is not `null`, or throws an exception. It checks that an argument is present, not that its contents are valid.
Object.toString returns an object's text representation. Overriding it lets you provide readable text useful for diagnostics.