HashSet.contains(Object) — test whether an element is present
`contains` checks whether a `HashSet` holds an element equal to the argument. It returns `true` or `false` without changing the set.
CKTIS / Java
Programming syntax, operators and concepts. Find an explanation, explore an example and return to learning.
`contains` checks whether a `HashSet` holds an element equal to the argument. It returns `true` or `false` without changing the set.
`size()` returns the current number of elements in a `HashSet` as an `int`. Adding an element that is already present does not increase the count.
`IdentityHashMap` matches keys with `==`, not `equals`. Learn when `put` replaces an entry, what `size` counts, and how to tell a missing key from one mapped to `null`.
InheritableThreadLocal<T> passes an initial value from a parent thread to a newly created child thread. Inheritance occurs when the thread is created, not at start() or when a task is submitted to a pool.
Use `Integer.compare` to compare two signed `int` values or sort items by ascending ID without relying on subtraction that can overflow.
Each successful call to `Integer(int)` creates a distinct wrapper object. In new code, use `Integer.valueOf(int)` or autoboxing when you need a wrapper, not a fresh identity.
`Integer.equals` checks the argument’s wrapper type and stored `int` value. With two `Integer` references, `==` checks object identity instead.
Use `Integer.hashCode(id)` for a primitive `int` and `boxed.hashCode()` for an `Integer` object. Both return the same numeric value as the hash code.
`Integer.max(a, b)` compares two signed `int` values and returns the larger one as an `int`. If both inputs are equal, it returns their common value.
Distinguish object identity from value equality, see when `==` unboxes an `Integer` to an `int`, and compare boxed values safely when either reference may be `null`.
Integer.parseInt(String) converts a decimal integer representation to int. Invalid text or an out-of-range value causes NumberFormatException.
`Integer.sum(a, b)` adds two `int` values just like `+`. Use `Integer::sum` when an API needs you to pass addition as a function.
Integer.toHexString represents an int as an unsigned hexadecimal String, using lowercase letters without unnecessary leading zeros.
Turn a primitive `int` into an `Integer`, distinguish boxing from parsing text, and see why wrapper identity is not a reliable test of numeric equality.
Check whether every `int` in a stream meets a condition, and learn why an empty stream returns `true`.
IntStream.count() returns the number of elements as a long, not the sum of their values. It is a terminal operation that counts elements remaining after earlier operations such as filter.
Create and filter streams of primitive `int` values, then distinguish the result types and empty-stream behavior of counting, summing, and averaging.
InvocationTargetException wraps an exception thrown by a reflectively invoked method or constructor. Read getCause() to identify the original problem instead of diagnosing only the wrapper exception.
Call `forEach` on an `Iterable` to run an action for each element. If the object specifies an iteration order, the method follows it unless the implementing class specifies otherwise.
The `iterator()` method returns an iterator that lets you step through the elements of an `Iterable` without using indexes.
`Iterator.hasNext()` checks whether an iterator has another element without consuming it. Use it as the loop condition before calling `next()`.
`Iterator.next()` returns the next element and advances the iterator. Use `hasNext()` to check whether an element remains.
Iterator.remove() deletes the element most recently returned by next() from the underlying collection, if the iterator supports removal.
io.BufferedReader: practical reference: BufferedReader buffers characters from a Reader and adds readLine; null means end of stream, while an empty line is returned as an empty string.