Scala String charAt() method with example
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 objectobject 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 objectobject 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


