Java String search character by index from start

Description

Java String search character by index from start


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

    // test indexOf to locate a character in a string
    System.out.printf("'c' is located at index %d\n", letters.indexOf('c'));
    System.out.printf("'a' is located at index %d\n", letters.indexOf('a'));
    /*from   www. j a v  a 2 s. c  o m*/
    int fromPosition= 3;
    System.out.printf("'a' is located at index %d\n", letters.indexOf('a', fromPosition));
    System.out.printf("'$' is located at index %d\n\n", letters.indexOf('$'));

  }
}



PreviousNext

Related