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 object object GfG { // Main method def main(args : Array[String]) { // Creating a String val m 1 = "Nidhi" // Applying charAt() method val result = m 1 .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 m 1 = "Nidhi" // Applying charAt() method val result = m 1 .charAt( 0 ) // Displays output println(result) } } |
Output:
N
Please Login to comment...