Java String lastIndexOf()The java string lastIndexOf() method returns last index of the 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 lastIndexOf method in java. The signature of lastIndexOf 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 Returnslast index of the string Java String lastIndexOf() method exampleOutput: 6 Java String lastIndexOf(int ch, int fromIndex) Method ExampleHere, we are finding last index from the string by specifying fromIndex Output: 3 Java String lastIndexOf(String substring) Method ExampleIt returns the last index of the substring. Output: 19 Java String lastIndexOf(String substring, int fromIndex) Method ExampleIt returns the last index of the substring from the fromIndex. Output: 19 -1 Next TopicJava String length()
|