Java StringBuffer indexOf Example

StringBuffer class indexOf method example. This example shows you how to use indexOf method.


StringBuffer class indexOf method example. This example shows you how to use indexOf method.public int indexOf(String str) Returns the index within this string of the first occurrence of the specified substring. The integer returned is the smallest value k such that: this.toString().startsWith(str, k) is true.

Here is the code
/**
 * @(#)  IndexOf.java
 * A class representing indexOf method
 * @Version  01-May-2008
 @author   Rose India Team
 */

public class IndexOf {
  public static void main(String args[]) {
    StringBuffer sb = new StringBuffer("india");
  
  //Returns the index of the specified substring.  
    System.out.println("Index of substring  :" + sb.indexOf("i"));
  
  //Returns the index of the specified substring, starting at the specified index.
  System.out.println("Index of substring  :" + sb.indexOf("i",2));
  }
}

null

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US