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

15th Sep 2018, 4:08 PM
Harsh Agrawal
Harsh Agrawal - avatar
4 Respostas
+ 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 â˜șâ˜șâ˜șïžđŸ€ŸđŸ€Ÿâ˜ïžâ˜ïž
15th Sep 2018, 4:17 PM
Rishabh
Rishabh - avatar
+ 2
Rishabh if d argument consist of a string and a number den how wll the output come???
16th Sep 2018, 3:05 AM
Harsh Agrawal
Harsh Agrawal - avatar
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
16th Sep 2018, 7:33 AM
Dan Walker
Dan Walker - avatar
0
eg String x = "Abcd123"; System.out.println(x.indexOf('b')); System.out.println (x.indexOf('3')); output: 1 6
17th Sep 2018, 2:08 AM
‎ ‏‏‎Anonymous Guy