0
0
Kotlinprogramming~15 mins

Sequence operators (map, filter) in Kotlin - Mini Project: Build & Apply

Choose your learning style9 modes available
Using Sequence Operators: map and filter in Kotlin
📖 Scenario: You are working on a simple Kotlin program that processes a list of ages to find which people are adults and then convert their ages to a string format for display.
🎯 Goal: Build a Kotlin program that uses sequence operators map and filter to select adults (age 18 or older) from a list of ages and then convert those ages to strings.
📋 What You'll Learn
Create a list of ages with exact values
Create a sequence from the list
Use filter to keep only ages 18 or older
Use map to convert the filtered ages to strings
Print the resulting list of strings
💡 Why This Matters
🌍 Real World
Filtering and transforming data is common in apps that process user information, like showing only adult users or formatting data for display.
💼 Career
Understanding sequence operators like <code>map</code> and <code>filter</code> is essential for Kotlin developers working on data processing, Android apps, or backend services.
Progress0 / 4 steps
1
Create the list of ages
Create a list called ages with these exact integer values: 15, 22, 17, 30, 14, 19.
Kotlin
Need a hint?

Use listOf to create the list with the exact numbers.

2
Create a sequence from the list
Create a variable called ageSequence by calling asSequence() on the ages list.
Kotlin
Need a hint?

Use asSequence() on the ages list to create a sequence.

3
Filter adults and map to strings
Create a variable called adultAgesStrings by applying filter on ageSequence to keep ages 18 or older, then apply map to convert each age to a string, and finally convert the result to a list using toList().
Kotlin
Need a hint?

Use filter { it >= 18 } to keep adults, then map { it.toString() } to convert to strings, and toList() to get a list.

4
Print the resulting list
Write a println statement to print the adultAgesStrings list.
Kotlin
Need a hint?

Use println(adultAgesStrings) to display the list.