Open In App

Scala String indexOf(String str, int fromIndex) method with example

Last Updated : 03 Oct, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

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.

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:

9

Example #2:




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


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads