lastIndexOf() - String Methods in Java

This article is a part of String Methods in Java.
The lastIndexOf() method returns the index within the string of the last occurrence of the specified character. The parameter passed in this method can be of String type which represents the string to be searched, or of char type representing a character to be searched. We can pass one more parameter fromIndex which indicates the index from where the search should begin.

Return type

The return type of lastIndexOf() method is an int value. The integer represents the last occurrence of the specified parameter, if the output is -1 then it represents that the specified parameter never occurs.
Let us look at an example for this method.


Let us look at the output of the above.

String Methods lastIndexOf()
Fig.1- String Method - lastIndexOf()

Here the search begins from the length()-1 position and the specified parameters are searched accordingly.

Read More

Author : Satyam Kumar -

You will also like:

Snowflake Cloud Data Warehouse

What is Snowflake, and what can you do with Snowflake? In video article.

Learning Journal

Array Concatenation in Java

Learn how to join two or more arrays together in Java by various methods.

Learning Journal

What is Programming and Programming Language

"PROGRAMMING" is the word which we all come across quite often. Let us see what that means.

Learning Journal

Generate Random Number in Java

Look at the different methods to generate random numbers in Java.

Learning Journal

Dawn of Bigdata

Let us go through the birth of Bigdata.

Learning Journal