This is an off-by-one error. The first two parameters to replace(...) are the starting index of the substring to replace, inclusive, and the ending of the substring to replace, exclusive. By using the same value for both, you are in effect "replacing" the nothing between indexes 1 and 2. This inclusive/exclusive way of expressing a range is extremely common.

Answer from Kevin Krumwiede on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › java › stringbuffer-replace-method-in-java-with-examples
StringBuffer replace() Method in Java with Examples - GeeksforGeeks
December 13, 2021 - The StringBuffer.replace() is the inbuilt method which is used to replace the characters in a substring of this sequence with the characters in the specified String. Here simply the characters in the substring are removed and other char is inserted ...
🌐
Tutorialspoint
tutorialspoint.com › java › stringbuffer_replace.htm
Java - String Buffer replace() Method
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
Discussions

java - Replacing individual characters in a StringBuffer - Stack Overflow
I'm trying to replace the individual 'a' character in 'Amazon' by using the .replace method in Java. I know how to do this with Strings, but when I use the code below with StringBuffers, I get an ... More on stackoverflow.com
🌐 stackoverflow.com
java - How to use replaceAll() method in StringBuffer? - Stack Overflow
I need to replace multiple words in a string buffer. So I am looking for a replaceAll method in StringBuffer. So do we have it in StringBuffer? String method: str2 = str1.replaceAll(regex, subst... More on stackoverflow.com
🌐 stackoverflow.com
java - StringBuffer.replace javadoc - Stack Overflow
I am confused by the official Javadoc which says public StringBuffer replace(int start, int end, String str) Replaces the characters in a substring of this sequence with characters in the More on stackoverflow.com
🌐 stackoverflow.com
java - Replace all occurrences of a String using StringBuilder? - Stack Overflow
Am I missing something, or does StringBuilder lack the same "replace all occurrences of a string A with string B" function that the normal String class does? The StringBuilder replace function isn't More on stackoverflow.com
🌐 stackoverflow.com
🌐
Tutorialspoint
tutorialspoint.com › java › lang › stringbuffer_replace.htm
Java StringBuffer replace() Method
The Java StringBuffer replace() method is used to replace the characters in a substring of a StringBuffer object with characters in the specified String. The substring begins at the specified start and extends to the character at index end - 1 or to
🌐
BeginnersBook
beginnersbook.com › 2014 › 08 › stringbuffer-replace-method-example
Java – StringBuffer Replace method Example
October 9, 2022 - //replace substring from index 4 to 9 by given string "hello" //4 is inclusive and 9 is exclusive sb.replace(4, 9, "hello"); public StringBuffer replace(int start, int end, String str): Replace the substring starting from start index till end index with the given string str.
🌐
Oracle
docs.oracle.com › javase › 7 › docs › api › java › lang › StringBuffer.html
StringBuffer (Java Platform SE 7 )
public StringBuffer replace(int start, int end, String str) Replaces the characters in a substring of this sequence 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 sequence if no such character ...
🌐
Javatpoint
javatpoint.com › java-stringbuffer-replace-method
Java StringBuffer replace() Method with Examples - Javatpoint
Java StringBuffer replace() Method with Examples on append(), capacity(), charAt(), delete(), indexOf(), getChars(), insert(), lastIndexOf(), length(), replace(), setCharAt(), setLength(), codePointAt(), codePointBefore(), codePointCount(), ensureCapacity() etc.
Find elsewhere
🌐
4JS
4js.com › online_documentation › fjs-fgl-2.50.02-manual-html › c_fgl_ClassStringBuffer_replace.html
base.StringBuffer.replace - 4Js
Replace one string with another · The replace() method replaces a string within the current string buffer with a different string. Specify the original string, replacement string, and the number of occurrences to replace. Use 0 to replace all occurrences
🌐
Java Tutorial HQ
javatutorialhq.com › java tutorial › java.lang › stringbuffer › replace(int start,int end,string str) method example
Java StringBuffer replace() method example
September 30, 2019 - package com.javatutorialhq.java.examples; /* * This example source code demonstrates the use of * replace(int start,int end,String str) method of StringBuffer class */ public class StringBufferReplace { public static void main(String[] args) { // initialize the StringBuffer object StringBuffer sb = new StringBuffer("javatutorialhq.com"); System.out.println("Contents of buffer:" + sb); int start = 2; int end = 5; String str = "VATUTO"; // Replace the characters from index 2 to index 5 sb.replace(start, end, str); System.out.println("New Contents of Buffer:"+sb); } }
🌐
Kodejava
kodejava.org › how-do-i-append-and-replace-content-of-a-stringbuffer
How do I append and replace content of a StringBuffer? - Learn Java by Examples
May 27, 2023 - package org.kodejava.lang; public class StringBufferAppendReplace { public static void main(String[] args) { StringBuffer quote = new StringBuffer("an apple "); char a = 'a'; String day = " day"; StringBuffer sentences = new StringBuffer(" keep the doctor away"); // Append a character into StringBuffer quote.append(a); System.out.println("quote = " + quote); // Append a string into StringBuffer quote.append(day); System.out.println("quote = " + quote); // Append another StringBuffer quote.append(sentences); System.out.println("quote = " + quote); // Replace a sub string from StringBuffer starting // from index = 3 to index = 8 quote.replace(3, 8, "orange"); System.out.println("quote = " + quote); } }
🌐
Tabnine
tabnine.com › home › code library
Code Library - Tabnine
July 25, 2024 - Get the answers and suggestions you need from our AI code assistant. Get started in minutes with a free 90 day trial of Tabnine Pro.
🌐
Coderanch
coderanch.com › t › 399643 › java › Replacing-character-StringBuffer
Replacing character in StringBuffer (Beginning Java forum at Coderanch)
May 12, 2005 - Replaces the characters in a substring of this StringBuffer with characters in the specified String. "'" throughout the value of StringBuffer wherver it is found.
🌐
Oracle
docs.oracle.com › javase › 6 › docs › api › java › lang › StringBuffer.html
StringBuffer (Java Platform SE 6)
public StringBuffer replace(int start, int end, String str) Replaces the characters in a substring of this sequence 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 sequence if no such character ...
🌐
Merit Campus
java.meritcampus.com › core-java-topics › java-stringbuffer-replace-method-with-example
Java StringBuffer replace() Method With Example
April 5, 2016 - Java StringBuffer replace() Method: This method replaces the characters in a substring of this sequence with characters in the specified String. First the characters in the substring are removed and then the specified String is inserted at start.
🌐
DEV Community
dev.to › eyalk100 › the-complete-guide-to-java-string-replace-4jde
The Complete Guide to Java String Replace - DEV Community
March 1, 2021 - Similar to StringBuilder.replace(), It’ll replace the substring sequence in the range passed as index parameters with the replacement String, but it’s thread-safe. Use this method when you want to perform the replace operation in a ...