The indexOf(String str, int fromIndex) method is utilized to return the index of the sub-string which occurs first from the index we specify in the string stated.
Scala
Scala
Method Definition: int indexOf(String str, int fromIndex) Return Type: It returns the index of the sub-string from the index specified in the argument.Example #1:
// Scala program of int indexOf()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Applying indexOf method
val result = "Nidhisinghis".indexOf("his", 4)
// Displays output
println(result)
}
}
Output:
Example #2:
9
// Scala program of int indexOf()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Applying indexOf method
val result = "Nidhisinghis".indexOf("is", 5)
// Displays output
println(result)
}
}
Output:
10