Java String search sub string from start

Description

Java String search sub string from start


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

    // test indexOf to locate a substring in a string
    System.out.printf("\"def\" is located at index %d\n", letters.indexOf("def"));

    int fromPosition = 7;
    System.out.printf("\"def\" is located at index %d\n", letters.indexOf("def", fromPosition));
    System.out.printf("\"hello\" is located at index %d\n\n", letters.indexOf("hello"));

  }/* w  w  w  .  j a  v  a2  s .  c o m*/
}



PreviousNext

Related