Ivan
Ivan

Reputation: 64207

What exact class does Java use for arrays and how to instantiate it in Scala?

I need to pass a 2-dimensional Java array of primitive values defined as

int myArray[][] = {{ 1, 2 }, { 3, 4 }, { 5, 6 }, { 7, 8 }};

in Java terms into a Java library function from a Scala application.

How to define such an object in Scala?

Upvotes: 0

Views: 150

Answers (1)

Leif Wickland
Leif Wickland

Reputation: 3724

The equivalent Scala to your Java is:

val myArray = Array(Array(1, 2), Array(3, 4), Array(5, 6), Array(7, 8))

Scala uses the exact same Array that Java does. An Array in Scala appears to have additional functionality because arrays are implicitly wrapped by WrappedArray.

For much more, see this answer.

Upvotes: 5

Related Questions