Must know operations on Collections in Kotlin

val list = listOf(-12, -5, 1, 9, 11)
  1. Filter : You have to create a list of positive numbers from above list. To achieve this ,typical code is
val result = mutableListOf<Int>()
for (num in list) {
if (num > 0) {
result += num
}
}
return result
val result = list.filter{it > 0}
val list = listOf("a", "b", "c", "d")
val result = mutableListOf<String>()for (str in list) {
result += num.uppercase()
}
return result
val result = list.map { it.toUppercase()}

--

--

--

Software developer @Riyaz

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Custom ListView in android with item click

How to implement Floating Action Button with Animation in Android (without plugin)

Build opencv4.0.1 & opencv_contrib for Android on macOS

How to Create Custom AppBar/ActionBar/ToolBar in Android Studio | Java

Now in Android #36

Android App Startup Tip: Don’t Use Kotlin Coroutines (Retracted)

Why RecyclerView? What is the difference between ListView and RecyclerView in Android?

How to fix ! Some Android licenses not accepted issue in Android Studio?

How to fix ! Some Android licenses not accepted issue in Android Studio?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Raj kumar

Raj kumar

Software developer @Riyaz

More from Medium

Integration of Huawei Push Kit in Book Reading Android app (Kotlin) — Part 3

Classifying categorical data in Weka via the API

What’s the tricky part of Gson?

Open camera and display image using kotlin