<div dir="ltr" style="text-align: left;" trbidi="on"><b>Description:</b></p>
<p> This method has following variants:</p>
<p></p>
<ul style="text-align: left;">
<li><b>int lastIndexOf(int ch):</b> Returns the index within this string of the last occurrence of the specified character or -1 if the character does not occur.</li>
</ul>
<p></p>
<ul style="text-align: left;">
<li><b>public int lastIndexOf(int ch, int fromIndex): </b>Returns the index of the last occurrence of the character in the character sequence represented by this object that is less than or equal to fromIndex, or -1 if the character does not occur before that point.</li>
</ul>
<p></p>
<ul style="text-align: left;">
<li><b>public int lastIndexOf(String str):</b> If the string argument occurs one or more times as a substring within this object, then it returns the index of the first character of the last such substring is returned. If it does not occur as a substring, -1 is returned.</li>
</ul>
<p></p>
<ul style="text-align: left;">
<li><b>public int lastIndexOf(String str, int fromIndex):</b> Returns the index within this string of the last occurrence of the specified substring, searching backward starting at the specified index.</li>
</ul>
<p>
 <b>Syntax:</b></p>
<p> Here is the syntax of this method:</p>
<pre class="highlight" name="code">int lastIndexOf(int ch)

or

public int lastIndexOf(int ch, int fromIndex)

or

public int lastIndexOf(String str)

or

public int lastIndexOf(String str, int fromIndex)
</pre>
<p>
<b>Parameters:</b></p>
<p> Here is the detail of parameters:</p>
<p></p>
<ul style="text-align: left;">
<li><b>ch</b> &#8212; a character.</li>
<li><b>fromIndex </b>&#8212; the index to start the search from.</li>
<li><b>str </b>&#8212; A string.</li>
</ul>
<p>
 <b>Return Value:</b></p>
<p> This method returns the index.</p>
<p> <b>Example:</b></p>
<pre class="highlight" name="code">import java.io.*;

public class Test {

 public static void main(String args[]) {
 String Str = new String("Welcome to dineshonjava.com");
 String SubStr1 = new String("Dinesh Tutorials" );
 String SubStr2 = new String("Good Tutorials" );

 System.out.print("Found Last Index :" );
 System.out.println(Str.lastIndexOf( 'o' ));
 System.out.print("Found Last Index :" );
 System.out.println(Str.lastIndexOf( 'o', 5 ));
 System.out.print("Found Last Index :" );
 System.out.println( Str.lastIndexOf( SubStr1 ));
 System.out.print("Found Last Index :" );
 System.out.println( Str.lastIndexOf( SubStr1, 15 ));
 System.out.print("Found Last Index :" );
 System.out.println(Str.lastIndexOf( SubStr2 ));
 }
}
</pre>
<p>
This produces following result:</p>
<div style="background-color: #ff99cc;"><b>output:</b><br />
Found Last Index :25<br />
Found Last Index :4<br />
Found Last Index :-1<br />
Found Last Index :-1<br />
Found Last Index :-1</div>
<p></p>
<div style="background-color: pink; border-width: thin; text-align: center;"><b><;<;<a href="https://dineshonjava.com/2013/02/string-class-in-java.html">Previous</a> <;<; ; ; || <a href="https://dineshonjava.com/2013/01/core-java-baby-step-to-be-best-java-ian.html">Index </a>||  ; >;>;<a href="https://dineshonjava.com/2013/03/java-string-length-method.html">Next</a> >;>;</b></div>
</div>
<div class="wp-post-navigation"> 
									 <div class="wp-post-navigation-pre"> 
									 <a href="https://dineshonjava.com/java-string-intern-method/">Previous</a> 
									 </div> 
									 <div class="wp-post-navigation-next"> 
									 <a href="https://dineshonjava.com/java-string-length-method/">Next</a> 
									 </div> 
									</div>
<script type="text/javascript">
jQuery(document).ready(function($) {
 $.post('https://dineshonjava.com/wp-admin/admin-ajax.php', {action: 'mts_view_count', id: '539'});
});
</script>
Strategy Design Patterns We can easily create a strategy design pattern using lambda. To implement…
Decorator Pattern A decorator pattern allows a user to add new functionality to an existing…
Delegating pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows…
Technology has emerged a lot in the last decade, and now we have artificial intelligence;…
Managing a database is becoming increasingly complex now due to the vast amount of data…
Overview In this article, we will explore Spring Scheduler how we could use it by…