Open In App

Scala String getBytes() method with example

Improve
Improve
Like Article
Like
Save
Share
Report

The getBytes() method is utilized to encode a stated string into a series of bytes and then it stores it into a new byte array. Moreover, here platforms default charset is utilized.

Method Definition: byte getBytes()
Return Type: It returns a new byte array storing series of bytes.

Example #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)
      
    }


Output:

[B@506e1b77

Example #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)
          
    }


Output:

[B@506e1b77


Last Updated : 03 Oct, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads