Iterable.iterator() — getting an iterator
The `iterator()` method returns an iterator that lets you step through the elements of an `Iterable` without using indexes.
CKTIS / Knowledge base
Programming syntax, operators and concepts. Find an explanation, explore an example and return to learning.
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.
io.BufferedWriter: practical reference: BufferedWriter buffers characters before forwarding them to a Writer; flush or close is required when downstream visibility matters.
ByteArrayInputStream exposes a byte array as an input stream. Its close() does not prevent further reads.
ByteArrayOutputStream collects bytes in memory. Learn writing, independent data snapshots, and why close() has no effect.
io.InputStream: practical reference: InputStream is the base byte-input abstraction; read returns 0..255 or -1 at end of stream, and bulk reads may be partial.
io.IOException: practical reference: IOException is the checked base exception for failed or interrupted I/O operations.
ObjectInputStream reconstructs objects from Java's binary serialization stream. Learn readObject(), exception handling, and closure through close(), while recognizing that deserializing untrusted data is dangerous.
ObjectOutputStream writes objects as a Java serialization byte stream. Learn writeObject, the distinction between flush and close, and automatic closure with try-with-resources.
io.OutputStream: practical reference: OutputStream is the base byte-output abstraction; close can release external resources and flush pushes buffered bytes.
io.Reader: practical reference: Reader is the base character-input abstraction; read returns UTF-16 code units or -1 and does not itself select a byte encoding.
io.Serializable: practical reference: Serializable is a marker enabling Java object serialization, but it does not promise a stable or safe cross-version format.
io.StringReader: practical reference: StringReader presents a String as a character Reader without external I/O.
io.StringWriter: practical reference: StringWriter collects characters in a StringBuffer; close has no effect and getBuffer exposes mutable backing storage.
io.Writer: practical reference: Writer is the base character-output abstraction and may buffer data that must be flushed or closed.
lang.ArithmeticException: practical reference: ArithmeticException signals an exceptional arithmetic condition such as integral division by zero; floating-point division follows IEEE 754.
ArrayIndexOutOfBoundsException signals array access with a negative index or an index greater than or equal to the array length. A valid index satisfies 0 <= index && index < array.length.
lang.AssertionError: practical reference: AssertionError is thrown when an enabled assert statement fails and should not replace validation of external input.
java.lang.AutoCloseable defines a resource-closing contract through close(). In try-with-resources, Java calls this method when leaving the block, including because of an exception, and closes multiple resources in reverse order.
Class<T> represents a type in a running program. It supports object checks and casts, plus inspection of names, member declarations, generic supertypes, and annotations. This entry targets Java SE 21; the repository runtime does not attest the production runtime.
lang.ClassCastException: practical reference: ClassCastException signals a run-time cast whose object is incompatible with the requested reference type.