Skip to content
Related Articles

Related Articles

Scala String indexOf(String str, int fromIndex) method with example
  • Last Updated : 03 Oct, 2019

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



My Personal Notes arrow_drop_up
Recommended Articles
Page :