StringBuilder.replace(int start, int end, String str) has the following syntax.
public StringBuilder replace(int start, int end, String str)
In the following code shows how to use StringBuilder.replace(int start, int end, String str) method.
public class Main { public static void main(String args[]) { StringBuilder sb = new StringBuilder("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.