Monday 7 July 2014

indexOf (String str, int fromIndex)

public synchronized int indexOf(String str, int fromIndex)
Returns the index within this string of the first occurrence of the specified substring, starting at the specified index.

public class StringBufferIndexOf1 {
    public static void main(String args[]){
        StringBuffer str1 = new StringBuffer("abcbabbcdabc");
        System.out.print("Index of \"ab\" from index 0 ");
        System.out.println(str1.indexOf("ab", 0));
        System.out.print("Index of \"ab\" from index 1 ");
        System.out.println(str1.indexOf("ab", 1));
    }     
}

Output
Index of "ab" from index 0 0
Index of "ab" from index 1 4

1. Throws NullPointerException, if str is null.




Prevoius                                                 Next                                                 Home

No comments:

Post a Comment