Tutorials Point


  Java Basics
  Java Object Oriented
  Java Advanced
  Java Useful References
  Java Useful Resources
  Selected Reading

© 2011 TutorialsPoint.COM


  Home     References     Discussion Forums     About TP  

Java - String Buffer replace() Method


previous next AddThis Social Bookmark Button


Description:

This method replaces the characters in a substring of this StringBuffer with characters in the specified String.

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. First the characters in the substring are removed and then the specified String is inserted at start.

Syntax:

Here is the syntax of this method:

public StringBuffer replace(int start, int end, String str)

Parameters:

Here is the detail of parameters:

  • start : The beginning index, inclusive.

  • end : The ending index, exclusive.

  • str : String that will replace previous contents.

Return Value :

  • Returns the modified SringBuilder object.

Example:

public class Test{
   public static void main(String args[]){
      StringBuilder sb = new StringBuilder("abcdefghijk");
      sb.replace(3, 8, "ZARA");
      System.ou.println(sb); 
   }  
}

This produces following result:

abcZARAijk


previous next Printer Friendly



  

Advertisement

Online Image Processing

Indian Baby Names