Arwa Z
Arwa Z

Reputation: 1

How to convert an Array[Byte] to an Array[Int] in scala/spark?

I have an Array[Byte] and I want to convert it to an Array[Int]:

for example,

val x : Array[Byte] = Array(192.toByte, 168.toByte, 1.toByte, 9.toByte)

val y : Array[Int] = Array(192, 168, 1, 9)

How can I convert x to y ?

Upvotes: 0

Views: 1346

Answers (3)

Arwa Z
Arwa Z

Reputation: 1

I tried this and it works:

val y = x.map(_.toInt & 0xff).deep

Upvotes: 0

koiralo
koiralo

Reputation: 23099

You can use simply map

val y:Array[Int] = x.map(_.toInt)

Upvotes: 2

Sebastiaan van den Broek
Sebastiaan van den Broek

Reputation: 6331

Try this:

val y = x.map(_.toInt)

Upvotes: 1

Related Questions