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. This is lesson 4 of 4. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the Kotlin Academy learning path, and your progress syncs across the web and the CoddyKit app. The Kotlin Academy course includes 4 lessons in total.
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
Learn Kotlin with an AI tutor — free
Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.
- Courses
- 51
- Lessons
- 203
Frequently Asked Questions
Is the “Iterating and Transforming Collections with Standard Library” lesson free?
Yes — any 3 lessons of the Kotlin Academy learning path, including “Iterating and Transforming Collections with Standard Library”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The Kotlin Academy course includes 4 lessons in total.
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, so you can start here or from the beginning and move at your own pace. This is lesson 4 of 4.
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