Open In App

Scala String charAt() method with example

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

The charAt() method is utilized to return the character of the index passed in the argument.

Method Definition: char charAt(int index)
Return Type: It returns char for the index given in the argument.

Example #1:




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


Output:

d

Example #2:




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


Output:

N


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

Similar Reads