Open In App

Scala Char toInt() method with example

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

The toInt() method is utilized to convert a stated character into an integer or its ASCII value of type Int.

Method Definition: def toInt: Int

Return Type: It returns Integer or ASCII value of the corresponding character of type Int.

Example: 1#




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


Output:

65

Example: 2#




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


Output:

57


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads