Scala String indexOf() method with example
Last Updated :
03 Oct, 2019
The indexOf() method is utilized to find the index of the first appearance of the character in the string and the character is present in the method as argument.
Method Definition: int indexOf(int ch)
Return Type: It returns the index of the character stated in the argument.
Example #1:
object GfG
{
def main(args : Array[String])
{
val result = "Nidhi" .indexOf( 'i' )
println(result)
}
}
|
So, here the first occurrence of ‘i’ is at index one So, 1 is returned as output.
Example #2:
object GfG
{
def main(args : Array[String])
{
val result = "Nidhi" .indexOf( 'h' )
println(result)
}
}
|
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...