The lastIndexOf() method is utilized to return the index of the last appearance of the character we specify in the argument from the index we specify for the stated string.
Method Definition: int lastIndexOf(int ch, int fromIndex)
Return Type: It returns the index of the last appearance of the character in the argument from the index we specify.
Here, the searching begins from the index 4, from right to the left position and the one which is appearing first is returned.
Here, the method is not able to find the stated character while searching from left towards right from the index specified. So, it returns -1 here.