Search code examples
javastringbuffer

How StringBuffer delete works in java


In java, the StringBuffer function will work like this str="hello" like it is specified the str.delete(1,3). I wanted to know how it works, like how it takes the position

class StringBufferExample4 {  
  public static void main(String args[]) {  
    StringBuffer sb=new StringBuffer("Hello");  
    sb.delete(1,3);  
    System.out.println(sb); 
  }  
} 

it gives the output

Hlo

How?


Solution

  • StringBuffer delete() method removes the characters in a substring of this StringBuffer. The substring begins at the specified start and extends to the character at index end - 1 or to the end of the StringBuffer if no such character exists.

    from: http://www.tutorialspoint.com/java/stringbuffer_delete.htm