Demonstrate indexOf() and lastIndexOf(). : String Find Search « Data Type « Java Tutorial






class indexOfDemo {
  public static void main(String args[]) {
    String s = "Now is the time for all good men " + "to come to the aid of their country.";

    System.out.println(s);
    System.out.println("indexOf(t) = " + s.indexOf('t'));
    System.out.println("lastIndexOf(t) = " + s.lastIndexOf('t'));
    System.out.println("indexOf(the) = " + s.indexOf("the"));
    System.out.println("lastIndexOf(the) = " + s.lastIndexOf("the"));
    System.out.println("indexOf(t, 10) = " + s.indexOf('t', 10));
    System.out.println("lastIndexOf(t, 60) = " + s.lastIndexOf('t', 60));
    System.out.println("indexOf(the, 10) = " + s.indexOf("the", 10));
    System.out.println("lastIndexOf(the, 60) = " + s.lastIndexOf("the", 60));
  }
}








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.