Java Data Type Tutorial - Java StringBuffer.replace(int start, int end, String str)








Syntax

StringBuffer.replace(int start, int end, String str) has the following syntax.

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

Example

In the following code shows how to use StringBuffer.replace(int start, int end, String str) method.

 
public class Main {
  public static void main(String args[]) {
    StringBuffer sb = new StringBuffer("This is a test from java2s.com.");

    sb.replace(5, 7, "was");
    System.out.println("After replace: " + sb);
  }
}

The code above generates the following result.