如何在scala/spark中将数组[Byte]转换为数组[Int]



我有一个Array[Byte],我想将其转换为Array[Int]:

例如

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

如何将x转换为y?

您可以简单地使用映射

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

试试这个:

val y = x.map(_.toInt)

我试过这个,它有效:

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

最新更新