Skip to content
Related Articles

Related Articles

Scala String getBytes() method with example
  • Last Updated : 03 Oct, 2019

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



My Personal Notes arrow_drop_up
Recommended Articles
Page :