Scala - Demonstrate zip and zipWithIndex Methods Code Example

The code for Demonstrate zip and zipWithIndex Methods

val str = "abc pqr xyz"
var result = str.zip(0 to 10)
println(result)

result = str.zipWithIndex
println(result)

/*
Output:
Vector((a,0), (b,1), (c,2), ( ,3), (p,4), (q,5), (r,6), ( ,7), (x,8), (y,9), (z,10))
Vector((a,0), (b,1), (c,2), ( ,3), (p,4), (q,5), (r,6), ( ,7), (x,8), (y,9), (z,10))
*/
Code by IncludeHelp, on August 10, 2022 23:52

Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.