Reputation: 23
Let's say I have an array of Bytes
val base = [-2, 50, 48]
and I converted this array of Bytes to an array of Strings
val baseConverted = ["-2","50","48"]
Is there a way to convert 'baseConverted' back to 'base'?
Upvotes: 2
Views: 50
Reputation: 2851
Here is how one can do it using Array
:
val baseConverted = Array("-2", "50", "48")
val backToBase = baseConverted.map(_.toByte)
// Prints
// backToBase: Array[Byte] = Array(-2, 50, 48)
Upvotes: 0
Reputation: 22595
You just need to use toByte
from a String
on every element:
List("-2","50","48").map(_.toByte)
Upvotes: 3