Java StringBuffer lastIndexOf Example

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


StringBuffer class lastIndexOf method example. This example shows you how to use lastIndexOf method.Returns the index within this string of the rightmost occurrence of the specified substring. The rightmost empty string "" is considered to occur at the index value this.length(). The returned index is the largest value k such that this.toString().startsWith(str, k)

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

public class LastIndexOf {
  public static void main(String args[]) {
    StringBuffer sb = new StringBuffer("Rose India");

  //Returns the index within this string of the rightmost occurrence of the specified substring.
    System.out.println("Last Index : " + sb.lastIndexOf("n"));
  
  //Returns the index within this string of the last occurrence of the specified substring.
  System.out.println("Last Index : " + sb.lastIndexOf("n",5));
  }
}

null

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

HOME | COPYRIGHT | CONTACT US