The indexOf(String str) method is utilized to return the index of the sub-string which occurs first in the string stated.
Method Definition: indexOf(String str)
Return Type: It returns the index of the sub-string which is specified in the argument of the method.
Example #1:
// Scala program of int indexOf() // method // Creating object object GfG { // Main method def main(args:Array[String]) { // Applying indexOf method val result = "NidhiSingh".indexOf("dh") // Displays output println(result) } } |
chevron_right
filter_none
Output:
2
Example #2:
// Scala program of int indexOf() // method // Creating object object GfG { // Main method def main(args:Array[String]) { // Applying indexOf method val result = "NidhiSingh".indexOf("Sin") // Displays output println(result) } } |
chevron_right
filter_none
Output:
5
Recommended Posts:
- Scala String lastIndexOf(String str, int fromIndex) method with example
- Scala String indexOf(String str, int fromIndex) method with example
- Scala String lastIndexOf(String str) method with example
- Scala String startsWith(String prefix, int toffset) method with example
- Scala String regionMatches(int toffset, String other, int offset, int len) method with example
- Scala String startsWith(String prefix) method with example
- Scala String split(String regex, int limit) method with example
- Scala String contentEquals() method with example
- Scala String substring(int beginIndex, int endIndex) method with example
- Scala String subSequence() method with example
- Scala String equalsIgnoreCase() method with example
- Scala String endsWith() method with example
- Scala String compareToIgnoreCase() method with example
- Scala String charAt() method with example
- Scala String equals() method with example
- Scala String compareTo() method with example
- Scala String getBytes() method with example
- Scala String hashCode() method with example
- Scala String indexOf() method with example
- Scala String indexOf(int ch, int fromIndex) method with example
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

