1

I have a Array like below

val a1 = Array("a","b","c")
var a2= Array("Apple","Box","Cat")
var a3= Array("Angel","Ball","Count")

I can use zip function to make a tuple of two. But how can I get a result like below?

Array(("a","Apple","Angel"),("b","Box","Ball"),("c","Cat","Count"),)
Andronicus
  • 25,419
  • 17
  • 47
  • 88
abc_spark
  • 383
  • 3
  • 19

1 Answers1

1

You can iterate over indices and map:

val result = a1.indices.map(index => (a1(index), a2(index), a3(index)))

That will create a Vector. If you want an Array, simply: result.toArray.

Andronicus
  • 25,419
  • 17
  • 47
  • 88