Use lastIndexOf to find a substring in a string : String Find Search « Data Type « Java Tutorial






public class MainClass
{
   public static void main( String args[] )
   {
      String letters = "abcdefghijklmabcdefghijklm";

      System.out.printf( "Last \"def\" is located at index %d\n",
          letters.lastIndexOf( "def" ) );
       System.out.printf( "Last \"def\" is located at index %d\n",
          letters.lastIndexOf( "def", 25 ) );
       System.out.printf( "Last \"hello\" is located at index %d\n",
          letters.lastIndexOf( "hello" ) );
   }
}
Last "def" is located at index 16
Last "def" is located at index 16
Last "hello" is located at index -1








2.29.String Find Search
2.29.1.Find the latest index of any of a set of potential substrings.
2.29.2.Find the first index of any of a set of potential substrings.
2.29.3.Finds the first index within a String, handling null.
2.29.4.Finds the last index within a String from a start position, handling null.
2.29.5.Finds the n-th index within a String, handling null.
2.29.6.Use String.indexOf to locate a character in a string
2.29.7.Use String.lastIndexOf to find a character in a string
2.29.8.Use String.indexOf to locate a substring in a string
2.29.9.Use lastIndexOf to find a substring in a string
2.29.10.Demonstrate indexOf() and lastIndexOf().
2.29.11.Extract Substring with indexOf
2.29.12.Java String endsWith
2.29.13.Java String startsWith
2.29.14.Starts with, ignore case( regular expressions )
2.29.15.Ends with, ignore case( regular expressions )
2.29.16.Anywhere, ignore case( regular expressions )
2.29.17.Last occurrence of a character
2.29.18.Not found returns -1
2.29.19.A bubble sort for Strings.
2.29.20.Search a String to find the first index of any character in the given set of characters.
2.29.21.Search a String to find the first index of any character not in the given set of characters.