0

In scala, I know you can access the n'th element in an Array with Array(n), for example z(1) = (3, 4) for the array z:

z: Array[(Int, Int)] = Array((1,2), (3,4), (6,7), (8,9))

But how do I acsess the first element in the second element (which would be 3)?

1 Answer 1

5

(3, 4) is of type Tuple2.

You can access its first element via:

val first = z(1)._1

or:

val (first, _) = z(1)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.