Java Examples
Java aligned plain-text terminal table
Renders rows as a column-aligned plain-text table by padding each cell to its maximum width.
Java Base64 encode decode with validation
Encodes bytes to a Base64 string and decodes back, raising a clear error for malformed input.
Java field validation collecting error messages
Validates required fields and collects per-field error messages instead of throwing on the first one.
Java query string builder and parser
Encodes maps into URL query strings and decodes them back with UTF-8 percent-encoding.
Java flat JSON object parser with clear errors
Parses a flat JSON object with a regex and throws a descriptive error for malformed input.
Java HTTP GET JSON with timeout client
Performs an HTTP GET with connect and read timeouts and parses the body as a JSON object string.
Java fixed worker pool with error collection
Runs tasks on a bounded thread pool and collects every result or failure without losing ordering.
Java environment config loader with defaults
Reads environment variables into a typed config record, applying defaults and failing on bad values.
Java token bucket rate limiter class
Allows bursts up to a bucket size while enforcing a steady average rate of requests per second.
Java bounded LRU cache via LinkedHashMap
Implements a fixed-capacity least-recently-used cache by overriding removeEldestEntry.
Java multi-key comparator with nulls last
Builds a stable multi-key comparator that sorts by several fields and puts nulls at the end.
Java partition list into fixed-size chunks
Splits any list into consecutive sublists of at most n elements, keeping the original order.
Java stream file lines with try-with-resources
Reads a text file line by line using Files.lines, exposing it as an iterable list of trimmed strings.
Java recursive map deep clone and merge
Deep-copies nested maps and recursively merges two map trees without mutating the inputs.
Java capped exponential backoff retry helper
Retries a throwing task with capped exponential backoff and randomized jitter between attempts.