Loading...
Preparing your coding drills
Comprehensive reference for 34 Kotlin methods across 7 categories.
listOf
Creates an immutable list containing the specified elements. The returned list is read-only and does not support add, remove, or other mutating operations.
mutableListOf
Creates a mutable list containing the specified elements. The returned list supports add, remove, and other mutating operations.
map
Returns a list containing the results of applying the given transform function to each element in the original collection.
filter
Returns a list containing only elements matching the given predicate.
reduce
Accumulates a value starting with the first element and applying the operation from left to right to current accumulator value and each element. Throws an exception if the collection is empty.
flatMap
Returns a single list of all elements yielded from the results of the transform function being invoked on each element of the original collection.
sortedBy
Returns a list of all elements sorted according to natural sort order of the value returned by the specified selector function.
split
Splits the string into a list of substrings around occurrences of the specified delimiters.
trim
Returns a string having leading and trailing whitespace removed. Can also accept a predicate to trim specific characters.
replace
Returns a new string obtained by replacing all occurrences of the old value with the new value.
substring
Returns a substring of this string starting at the startIndex and ending right before the endIndex.
lowercase
Returns a copy of this string converted to lowercase using the rules of the default locale.
mapOf
Creates an immutable map from the given key-value pairs. The returned map preserves the entry iteration order.
mutableMapOf
Creates a mutable map from the given key-value pairs. Supports put, remove, and other mutating operations.
getOrDefault
Returns the value corresponding to the given key, or the specified default value if the key is not present in the map.
entries
Returns a read-only set of all key-value pairs in this map. Each entry contains the key and value properties.
any
Returns true if at least one element matches the given predicate. When called without a predicate, returns true if the collection is not empty.
all
Returns true if all elements match the given predicate. Returns true for an empty collection (vacuous truth).
first
Returns the first element matching the given predicate, or the first element of the collection if no predicate is provided. Throws NoSuchElementException if no matching element is found.
last
Returns the last element matching the given predicate, or the last element of the collection if no predicate is provided. Throws NoSuchElementException if no matching element is found.
find
Returns the first element matching the given predicate, or null if no such element was found. This is an alias for firstOrNull().
zip
Returns a list of pairs built from the elements of this collection and the other collection with the same index. The resulting list has the length of the shortest collection.
chunked
Splits the collection into a list of lists, each not exceeding the given size. The last list in the result may have fewer elements than the given size.
groupBy
Groups elements of the original collection by the key returned by the given keySelector function applied to each element and returns a map where each group key is associated with a list of corresponding elements.
let
Calls the specified function block with this value as its argument and returns its result. Commonly used for null-safety checks and transforming values within a chain.
run
Calls the specified function block with this value as its receiver and returns its result. Useful for initializing objects and computing results.
apply
Calls the specified function block with this value as its receiver and returns this value. Ideal for object configuration and builder-style initialization.
also
Calls the specified function block with this value as its argument and returns this value. Useful for performing additional actions that do not alter the object, such as logging or validation.
toInt
Parses the string as a signed Int number and returns the result. Throws NumberFormatException if the string is not a valid representation of an integer.
toString
Returns a string representation of the object. For nullable types, returns "null" if the object is null. Can be overridden by classes to provide custom string representation.
toList
Returns a new read-only list containing all elements of the original collection or iterable. Useful for converting sequences, sets, arrays, or other iterables to a List.
asSequence
Creates a lazy sequence from the collection. Sequence operations are evaluated lazily, meaning intermediate operations do not create new collections but are applied only when the terminal operation is invoked.
take
Returns a list containing the first n elements. If the collection has fewer than n elements, returns all elements.
drop
Returns a list containing all elements except the first n elements. If the collection has fewer than n elements, returns an empty list.