Skip to content
Related Articles

Related Articles

Scala String charAt() method with example
  • Last Updated : 15 Oct, 2019

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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)
          
    }

chevron_right


Output:

d

Example #2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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)
          
    }

chevron_right


Output:

N



My Personal Notes arrow_drop_up
Recommended Articles
Page :