java tutorial - Java Strings LastIndexOf() method - java programming - learn java - java basics - java for beginners



Java strings last index of

Learn Java - Java tutorial - Java strings last index of - Java examples - Java programs

Description

LastIndexOf () method The lastIndexOf () method in Java has the following options:

  • int lastIndexOf(int ch) — returns the index in the given line of the last occurrence of the specified character or -1 if the character does not occur.
  • int intIndexOf (int ch, int fromIndex) - returns the index of the last occurrence of the character in the character string represented by this object, which is less than or equal to fromIndex, or -1 if the character does not occur before this point.
  • public int lastIndexOf (String str) - if string argument occurs at least one times in the substring in a given object, and then it will returns index of the initial character of the very last substring.
  • public int lastIndexOf (String str, int fromIndex) - returns the index within the given line of the last occurrence of the specified substring, the search is performed back, starting with the specified index.

Syntax

Syntax method:


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)
click below button to copy the code. By - java tutorial - team

Options

Detailed information about the parameters:

  • ch is a character;
  • fromIndex - index to start the search (from);
  • str is a string.

Return value

  • In Java, lastIndexOf () returns an index.

Sample Code

import java.io.*;
public class Test {

   public static void main(String args[]) {
      String Str = new String("Welcome to wikitechy.com");
      System.out.print("Found Last Index :" );
      System.out.println(Str.lastIndexOf( 'o' ));
   }
}
click below button to copy the code. By - java tutorial - team

Output

Found Last Index :23

Related Searches to Java Strings LastIndexOf() method