Kotlin Examples

KotlinOct 23, 2026

Aligned plain-text table renderer for the terminal

Renders headers and rows as a pipe-delimited text table padded per column for readable terminal and log output.

formattingtablecli
000
KotlinOct 23, 2026

Base64 encode and validated decode helpers

Encodes UTF-8 text as Base64 and decodes it back, returning null for malformed input instead of throwing.

decodingencodingbase64
000
KotlinOct 23, 2026

Field-level validation returning an error map

Validates email, age, and password and returns a field-to-message map instead of throwing on the first error.

errorsvalidationforms
000
KotlinOct 23, 2026

Build and parse URL query strings in Kotlin

Percent-encodes a map into a query string and decodes one back into a map, tolerating missing equals signs and blank pairs.

urlsquery-stringencoding
000
KotlinOct 23, 2026

Flat JSON object parser with pointed errors

Decodes a flat JSON object and throws a descriptive exception naming the bad entry, an empty key, or a duplicate key.

parsingerrorsjson
000
KotlinOct 23, 2026

Fixed-size thread pool returning Kotlin Results

Runs each task on a fixed-size thread pool and returns one Result per task, so failures are collected instead of thrown.

concurrencyexecutorsthread-pool
000
KotlinOct 23, 2026

Kotlin HTTP GET JSON field with timeouts

Performs an HTTP GET with connect and read timeouts, checks the status code, then scans a quoted field from the JSON body.

timeoutshttpjson
000
KotlinOct 23, 2026

Typed environment config with validation errors

Reads environment variables with defaults, parses numbers, and fails fast with clear messages on invalid values.

environmentconfigurationvalidation
000
KotlinOct 23, 2026

Token bucket rate limiter with a refill clock

Allows short bursts up to the capacity while enforcing an average refill rate, using a synchronized acquire check.

concurrencytoken-bucketrate-limiting
000
KotlinOct 23, 2026

Multi-key sort of nullable records with compareBy

Sorts records by age with nulls last, then by join date descending and finally by lowercase name, stably.

sortingcomparatorsnull-safety
000
KotlinOct 23, 2026

LinkedHashMap-backed LRU cache with size bound

A size-bounded LinkedHashMap that refreshes recency on read or write and evicts the least recently used entry.

linkedhashmaplrucache
000
KotlinOct 23, 2026

Batch a Kotlin iterable into fixed-size lists

Groups iterable elements into lists of a fixed size, keeping order and returning a smaller final batch when needed.

batchingcollectionsiterables
000
KotlinOct 23, 2026

Stream a file line by line with useLines

Reads a text file lazily line by line with useLines, closing the handle automatically even when an exception is thrown.

lazylinesfile-io
000
KotlinOct 23, 2026

Deep clone and merge nested Kotlin maps

Recursively copies nested maps and lists, then merges a patch into a base map without mutating either input.

mergedeep-copycollections
000
KotlinOct 23, 2026

Kotlin retry loop with capped exponential backoff

Retries a block up to five times with capped exponential backoff and full jitter, sleeping only between attempts.

backoffretryjitter
000