Java String indexOf()The java string indexOf() method returns index of given character value or substring. If it is not found, it returns -1. The index counter starts from zero. Internal implementationSignatureThere are 4 types of indexOf method in java. The signature of indexOf methods are given below:
Parametersch: char value i.e. a single character e.g. 'a' fromIndex: index position from where index of the char value or substring is retured substring: substring to be searched in this string Returnsindex of the string Java String indexOf() method example2 8 5 3 Java String indexOf(String substring) Method ExampleThis method takes substring as an argument and returns index of first character of the substring. index of substring 16 Java String indexOf(String substring, int fromIndex) Method ExampleThis method takes substring and index as arguments and returns index of first character occured after the given fromIndex. index of substring 16 index of substring -1 Java String indexOf(int char, int fromIndex) Method ExampleThis method takes char and index as arguments and returns index of first character occured after the given fromIndex. index of char 17 Next TopicJava String intern
|