Open In App
Related Articles

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

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
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


Last Updated : 03 Oct, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads