0
Explain indexOf method???
Give suitable example so dat i can understand properly!!!! Dan Walker [A^dr3w] â âââSreejith Helga Purab Gupta Arun Tomar Fata1 Err0r
4 Answers
+ 3
If im not wrong its a method that gives the integer value index of specific characters in a string
For eg:
String name="Rishabh";
System.out.println (name.indexOf('s'));
It prints 2
Hope u understood âşď¸âşď¸âşď¸đ¤đ¤âď¸âď¸
+ 2
Rishabh if d argument consist of a string and a number den how wll the output come???
0
https://docs.oracle.com/javase/9/docs/api/java/lang/String.html#indexOf-java.lang.String-
All of the overloaded versions of indexOf return an int, the index of the first occurrence. If you put an int as a separate parameter this tells the start index to search from, so this could be used when you want to find subsequent occurrences. If you meant letters and numbers in the string argument then you get the index where that substring first occurs, otherwise -1 if you don't find it
0
eg
String x = "Abcd123";
System.out.println(x.indexOf('b'));
System.out.println (x.indexOf('3'));
output:
1
6