Skip to main content

List, Set, Map, and operator directory

Start by choosing the correct shape:

ShapeMeaningExample
List<T>Ordered; duplicates allowed; indexedSearch results
Set<T>Unique elements by equalitySelected IDs
Map<K, V>Unique keys associated with valuesUser by ID

See the behavioral differences​

fun main() {
val names: List<String> = listOf("Ada", "Ada", "Grace")
val uniqueNames: Set<String> = names.toSet()
val ages: Map<String, Int> = mapOf("Ada" to 36, "Grace" to 85)

println(names) // [Ada, Ada, Grace]
println(uniqueNames) // [Ada, Grace]
println(ages["Ada"]) // 36
println(ages["Missing"]) // null
}
Open in Kotlin Playground

A Set is not “a faster List.” It represents a different domain rule: duplicates have no meaning. A Map lookup is nullable because the requested key may not exist.

Transformation pipeline​

fun main() {
val numbers = listOf(1, 2, 3, 4)
val result = numbers
.filter { number -> number % 2 == 0 }
.map { number -> number * number }

println(numbers) // [1, 2, 3, 4]
println(result) // [4, 16]
}
Open in Kotlin Playground

filter creates the matching result; map creates one transformed value per input. Neither operation mutates numbers.

Complete operator directory​

Use this as a discovery index, then open the linked lesson for behavior, edge cases, output, and runnable examples.

FamilyImportant operationsDetailed lesson
Accessfirst, firstOrNull, last, lastOrNull, single, singleOrNull, getOrNull, elementAtOrNull, elementAtOrElse, random, randomOrNullAccess and search
Searchfind, indexOf, indexOfFirst, indexOfLastAccess and search
Filterfilter, filterNot, filterIndexed, filterNotNull, filterIsInstanceFiltering and types
Transformmap, mapIndexed, mapNotNull, flatMap, flattenAdvanced operations
Checkany, all, none, contains, containsAllAdvanced operations
Slicetake, drop, takeLast, dropLast, takeWhile, dropWhile, takeLastWhile, dropLastWhileAdvanced operations
List-specificslice, subList, binarySearch, zipWithNext, indexed mutations, fill, asReversedList operations
Map-specificgetValue, getOrElse, getOrPut, mapKeys, mapValues, filterKeys, filterValuesMap operations
Set algebraunion, intersect, subtractSet algebra
Sortsorted, sortedDescending, sortedBy, sortedWith, sortBy, reversed, shuffledSorting
Aggregatesum, sumOf, average, count, minByOrNull, maxByOrNull, fold, reduce, runningFold, foldRightBasic / advanced
GroupgroupBy, groupingBy, eachCountGrouping
Map creationassociate, associateBy, associateWithAssociation
Uniquedistinct, distinctBy, toSetAdvanced operations
Combinezip, unzip, plus, minusAdvanced operations
Splitpartition, chunked, windowedAdvanced operations
Mutationadd, addAll, remove, removeAt, clear, retainAllMutation and copying
Destinations/buildersfilterTo, mapTo, associateTo, groupByTo, buildList, buildSet, buildMapDestination/build operations

Predict the output​

fun main() {
val values = listOf(1, 2, 2, 3)
val changed = values
.toSet()
.map { it * 10 }

println(values)
println(changed)
}
Reveal

The original remains [1, 2, 2, 3]. The Set removes the duplicate, and map returns [10, 20, 30] for the current insertion-preserving implementation. Do not treat incidental ordering from an arbitrary Set implementation as a universal business guarantee.

Open in Kotlin Playground
Interview-ready foundation

Choose List, Set, or Map from the domain's cardinality and ordering rules. Then choose operators by behavior: throwing versus nullable, first match versus all matches, new result versus mutation, one value per key versus many, eager versus lazy, and silent duplicate replacement versus validation.