February 2018
Intermediate to advanced
350 pages
7h 35m
English
The zip function does exactly what it sounds like, it zips collections. Confusing? Let's have a look at the following example:
fun main(args: Array<String>) {
val list1 = listOf(1,2,3,4,5)
val list2 = listOf(
"Item 1",
"Item 2",
"Item 3",
"Item 4",
"Item 5"
)
val resultantList = list1.zip(list2)
println(resultantList)
}
We created two lists—one with Int and the other with String. We then created a resultant list by zipping the Int list with the String list and printed the resultant list.
So, what does the resultantList value contain? What operation did the zip function perform?
Let us decide it ourselves by having a look at the following output:
Amazing, isn't it? The zip function takes another collection, combines the ...
Read now
Unlock full access