Iterating and Transforming Collections with Standard Library
Use map, filter, any, all, count on real collection examples.
Iterating and Transforming Collections with Standard Library is a free Kotlin Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Kotlin Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Collections as Pipelines
map: One-to-One Transformation
val prices = listOf(10, 20, 30)
val withTax = prices.map { it * 1.1 }
println(withTax) // [11.0, 22.0, 33.0]flatMap: One-to-Many
val sentences = listOf("hello world", "foo bar")
val words = sentences.flatMap { it.split(" ") }
println(words) // [hello, world, foo, bar]filter and filterNot
val nums = (1..10).toList()
val evens = nums.filter { it % 2 == 0 }
val odds = nums.filterNot { it % 2 == 0 }
println(evens) // [2, 4, 6, 8, 10]groupBy: Bucket by Key
val words = listOf("one", "two", "three", "four", "five")
val byLength = words.groupBy { it.length }
println(byLength)
// {3=[one, two], 5=[three], 4=[four, five]}associate and associateBy
val items = listOf("apple", "banana", "cherry")
val byFirst = items.associateBy { it.first() }
println(byFirst) // {a=apple, b=banana, c=cherry}partition: Split Into Two
val (evens, odds) = (1..8).partition { it % 2 == 0 }
println(evens) // [2, 4, 6, 8]
println(odds) // [1, 3, 5, 7]distinct and distinctBy
val nums = listOf(1, 2, 2, 3, 1, 4)
println(nums.distinct()) // [1, 2, 3, 4]
val words = listOf("Hi", "hello", "HI")
println(words.distinctBy { it.lowercase() })take, drop, and chunked
val list = (1..10).toList()
println(list.take(3)) // [1, 2, 3]
println(list.drop(7)) // [8, 9, 10]
println(list.chunked(3)) // [[1,2,3],[4,5,6],[7,8,9],[10]]zip: Pair Two Collections
val names = listOf("Alice", "Bob", "Charlie")
val scores = listOf(90, 85, 92)
val combined = names.zip(scores)
println(combined) // [(Alice, 90), (Bob, 85), (Charlie, 92)]sumOf, minOf, maxOf, averageOf
val items = listOf("apple", "banana", "cherry")
println(items.sumOf { it.length }) // 18
println(items.maxOf { it.length }) // 6
println(items.minOf { it.length }) // 5Quick Check
Recap
Frequently asked questions
Is the “Iterating and Transforming Collections with Standard Library” lesson free?
Yes — the full text of “Iterating and Transforming Collections with Standard Library” is free to read here on the web, and the Kotlin Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Kotlin Academy course, upgrade to CoddyKit PRO.
What will I learn in “Iterating and Transforming Collections with Standard Library”?
Use map, filter, any, all, count on real collection examples. You practise Kotlin Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Kotlin Academy?
No prior experience is required. Kotlin Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Iterating and Transforming Collections with Standard Library” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Kotlin Academy lesson?
Yes. Every Kotlin Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- listOf, setOf, mapOf: Read-Only Collections
- mutableListOf, mutableMapOf: Mutable Builders
- Accessing Elements: get, first, last, getOrNull
- Iterating and Transforming Collections with Standard Library