Tuesday 17 June 2014

indexOf (int ch)

public int indexOf(int ch)
Returns the index within this string of the first occurrence of the specified character or -1 if the character does not occur.

class StringIndexOf{
 public static void main(String args[]){
  String s1 = new String("wxyzbab");
  System.out.println("s1 = " + s1);
  
  System.out.print("Character b at index ");
  System.out.println(s1.indexOf('b'));
  
  System.out.print("Character h at index ");
  System.out.println(s1.indexOf('h'));
 }
}

Output
s1 = wxyzbab
Character b at index 4
Character h at index -1



Prevoius                                                 Next                                                 Home

No comments:

Post a Comment