Skip to content
Related Articles
Get the best out of our app
GFG App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Scala String charAt() method with example

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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

My Personal Notes arrow_drop_up
Last Updated : 15 Oct, 2019
Like Article
Save Article
Similar Reads