Scala 字符串 getBytes()方法及示例
getBytes() 方法是用来将所述的字符串编码成一系列的字节,然后将其存入一个新的字节数组。此外,这里利用了平台的默认字符集。
方法定义:byte getBytes()
返回类型。它返回一个存储一系列字节的新字节数组。
例子 #1 :
// Scala program of getBytes()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Applying getBytes method
val result = "Nidhi".getBytes()
// Displays output
println(result)
}
}
输出。
[B@506e1b77
例子#2 。
// Scala program of getBytes()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Applying getBytes method
val result = " ".getBytes()
// Displays output
println(result)
}
}
输出。
[B@506e1b77
极客教程