Java String lastIndexOf() method

Java String lastIndexOf() method returns last index of character or substring in a String.

Syntax:     

                 Method                                                  Description

int lastIndexOf(int ch) It returns last index position for the given char value
int lastIndexOf(int ch, int fromIndex) It returns last index position for the given char value and from index
int lastIndexOf(String substring) It returns last index position for the given substring
int lastIndexOf(String substring, int fromIndex) It returns last index position for the given substring and from index

Parameter

ch   :  a single character

fromIndex  : index position from where index of the char value or substring is returned

substring : substring to be searched in current String

Returns

It returns last index of the given String

Java String lastIndexOf() method example

Output:

Java String lastIndexOf(int ch, int fromIndex) method example

Output:

Java String lastIndexOf(String substring) method example  

Output:

Java String lastIndexOf(String substring, int fromIndex) method example

Output:

Leave a Comment