java tutorial - Java StringBuffer replace() method - java programming - learn java - java basics - java for beginners



Java  stringbuffer replace

Learn Java - Java tutorial - Java stringbuffer replace - Java examples - Java programs

Description

The replace () method — replaces the specified characters in the string with the substring of the given buffer string (StringBuffer).

  • In other words, the method allows in Java to replace the characters in the string between the specified start and end indexes.

Syntax

Syntax method:

public StringBuffer replace(int start, int end, String str)
click below button to copy the code. By - java tutorial - team

Options

Detailed information about the parameters:

  • start - initial index, inclusive;
  • end - end index, not including;
  • str is a string that will replace the previous contents.

Return value

  • In Java replace (), returns the modified SringBuffer object.

Sample Code

public class Test {
 public static void main(String args[]) {
      StringBuffer sb = new StringBuffer("best batsman");
      sb.replace(3, 9, "sachin");
      System.out.println(sb); 
   }  
}
click below button to copy the code. By - java tutorial - team

Output

bessachinman

Related Searches to Java StringBuffer replace() method