Java Examples

JavaOct 23, 2026

Java aligned plain-text terminal table

Renders rows as a column-aligned plain-text table by padding each cell to its maximum width.

formattingtableterminalcli
000
JavaOct 23, 2026

Java Base64 encode decode with validation

Encodes bytes to a Base64 string and decodes back, raising a clear error for malformed input.

bytesencodingbase64
000
JavaOct 23, 2026

Java field validation collecting error messages

Validates required fields and collects per-field error messages instead of throwing on the first one.

errorsvalidationforms
000
JavaOct 23, 2026

Java query string builder and parser

Encodes maps into URL query strings and decodes them back with UTF-8 percent-encoding.

queryurlencoding
000
JavaOct 23, 2026

Java flat JSON object parser with clear errors

Parses a flat JSON object with a regex and throws a descriptive error for malformed input.

parsingerrorsjson
000
JavaOct 23, 2026

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.

clienthttpjsontimeout
000
JavaOct 23, 2026

Java fixed worker pool with error collection

Runs tasks on a bounded thread pool and collects every result or failure without losing ordering.

concurrencythreadsexecutor
000
JavaOct 23, 2026

Java environment config loader with defaults

Reads environment variables into a typed config record, applying defaults and failing on bad values.

configenvvalidation
000
JavaOct 23, 2026

Java token bucket rate limiter class

Allows bursts up to a bucket size while enforcing a steady average rate of requests per second.

concurrencytoken-bucketrate-limit
000
JavaOct 23, 2026

Java bounded LRU cache via LinkedHashMap

Implements a fixed-capacity least-recently-used cache by overriding removeEldestEntry.

lrucachecollections
000
JavaOct 23, 2026

Java multi-key comparator with nulls last

Builds a stable multi-key comparator that sorts by several fields and puts nulls at the end.

sortnullsrecordscomparator
000
JavaOct 23, 2026

Java partition list into fixed-size chunks

Splits any list into consecutive sublists of at most n elements, keeping the original order.

listchunkpartitionbatch
000
JavaOct 23, 2026

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.

linesioniofiles
000
JavaOct 23, 2026

Java recursive map deep clone and merge

Deep-copies nested maps and recursively merges two map trees without mutating the inputs.

mergerecursionclonemap
000
JavaOct 23, 2026

Java capped exponential backoff retry helper

Retries a throwing task with capped exponential backoff and randomized jitter between attempts.

backoffretryjitter
000