You are here: Home / Topics / lastIndexOf() method example in Java

lastIndexOf() method example in Java

Filed under: Java on 2023-08-23 18:54:29

// Program to explain the following String function :
// int lastIndexOf( String str )

class  MlastIndexOf
{
public static void main( String args[ ] )
{
 String s1 = "Java Programming Examples Java Programming Examples.";
   
 System.out.println( " Last Index of " + 'P' + " = " + s1.lastIndexOf( 'P' ) );
 System.out.println( " Last Index of " + 'x' + " = " + s1.lastIndexOf( 'x' ) );
 System.out.println( " Last Index of " + "Programming" + " = " + s1.lastIndexOf( "Programming" ) );
 System.out.println( " Last Index of " + "JAVA" + " = " + s1.lastIndexOf( "JAVA" ) );
}
}


Output:

Last Index of P = 31
Last Index of x = 44
Last Index of Programming = 31
Last Index of JAVA = -1

About Author:
J
Java     View Profile
Hi, I am using MCQ Buddy. I love to share content on this website.