Last active
March 22, 2020 13:11
-
-
Save shahsurajk/44693931ece956ad6cd0c01ccb9bbbb1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val colorsList = listOf("blue", "red", "black", "yellow") | |
val list1: List<String> = colorsList | |
.filter { it != "red" } // new array list of size 3 | |
.map { it.toLowerCase() } // new array list of size 4 | |
.take(2) // new array list of size 2 | |
val list2: List<String> = colorsList | |
.asSequence() | |
.filter { it != "red" } // will run and take "blue" and "black" | |
.map { it.toLowerCase()} // new array list of default size | |
.take(2) // will run 3 iterations and then exit with just one array instance | |
.toList() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment