Open In App

Scala String toString() method with example

Last Updated : 29 Oct, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

The toString() method is utilized to return a string object itself.

Method Definition: String toString()

Return Type: It returns the string object.

Example: 1#




// Scala program of toString()
// method
  
// Creating object
object GfG
  
    // Main method
    def main(args:Array[String])
    {
      
        // Applying toString method
        val result = "GEEKS".toString()
          
        // Displays output
        println(result)
      
    }


Output:

GEEKS

Example: 2#




// Scala program of toString()
// method
  
// Creating object
object GfG
  
    // Main method
    def main(args:Array[String])
    {
      
        // Applying toString method
        val result = "10".toString()
          
        // Displays output
        println(result)
          
    }


Output:

10


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads