It would be a mistake to judge the value of String against StringBuffer on a single point. Yes they are very similar in functionality when taking substrings. No this does not contribute to the argument as to whether to use one or the other.

You should always use the best structure. String is immutable and should be used when immutability is required and in some edge cases. If you need to make changes to a CharSequence then it would be better/safer/faster/more memory efficient to use StringBuilder.

Consider removing a part of a string. Compare how you can do it using a String and using a StringBuilder - see how much easier it is. It isn't just easier, it is more efficient. The String mechanism creates two new objects and then adds them together to make a third. The StringBuilder one just removes the section of the string.

public void test() {
    String a = "0123456789";
    StringBuilder b = new StringBuilder(a);
    System.out.println("a=" + a + " b=" + b);
    a = a.substring(0, 2) + a.substring(5);
    b.delete(2, 5);
    System.out.println("a=" + a + " b=" + b);
}
Answer from OldCurmudgeon on Stack Overflow
🌐
Tutorialspoint
tutorialspoint.com › java › lang › stringbuffer_substring.htm
Java StringBuffer substring() Method
The Java StringBuffer substring() method is, used to retrieve a desired subsequence from a StringBuffer object. The substring is a small part of the given string. By default, This substring begins at the specified index and extends to the end of
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › StringBuffer.html
StringBuffer (Java Platform SE 8 )
April 21, 2026 - public StringBuffer delete(int start, int end) Removes the characters in a substring of this sequence. 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 exists. If start is equal to end, no changes are made.
🌐
Tutorialspoint
tutorialspoint.com › java › lang › stringbuffer_substring_end.htm
Java.lang.StringBuffer.substring() Method
The java.lang.StringBuffer.substring(int start, int end) method returns a new String that contains a subsequence of characters currently contained in this sequence. The substring begins at the specified start and extends to the character at index end - 1. Following is the declaration for ...
🌐
GeeksforGeeks
geeksforgeeks.org › java › stringbuffer-substring-method-in-java-with-examples
StringBuffer substring() method in Java with Examples - GeeksforGeeks
July 30, 2019 - The substring(int start, int end) method of StringBuffer class is the inbuilt method used to return a substring start from index start and extends to the index end-1 of this sequence.
🌐
BeginnersBook
beginnersbook.com › 2014 › 08 › stringbuffer-substring-method-example
Java – StringBuffer substring method Example
October 9, 2022 - Returns a substring based on the specified indexes. class JavaExample{ public static void main(String[] args) { StringBuffer sb = new StringBuffer("BeginnersBook"); //substring begins from index 9 String subStr = sb.substring(9); System.out.println("Substring from index 9: "+subStr); } }
🌐
Oracle
docs.oracle.com › javase › 7 › docs › api › java › lang › StringBuffer.html
StringBuffer (Java Platform SE 7 )
public StringBuffer delete(int start, int end) Removes the characters in a substring of this sequence. 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 exists. If start is equal to end, no changes are made.
Find elsewhere
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › java.lang.stringbuffer.substring
StringBuffer.Substring Method (Java.Lang) | Microsoft Learn
[<Android.Runtime.Register("substring", "(II)Ljava/lang/String;", "")>] override this.Substring : int * int -> string ... Added in 1.2. Java documentation for java.lang.StringBuffer.substring(int, int).
🌐
Java Tutorial HQ
javatutorialhq.com › java tutorial › java.lang › stringbuffer › substring(int start, int end) method example
Java StringBuffer substring(int start, int end) method example
September 30, 2019 - This is similar however in this case we specified the end index as method argument not unlike the other one which implicitly have the end index as the stringbuffer length. package com.javatutorialhq.java.examples; /* * This example source code demonstrates the use of * substring(int start,int end) method of StringBuffer class */ public class StringBufferSubstringStartEnd { public static void main(String[] args) { // initialize the StringBuffer object StringBuffer sb = new StringBuffer("javatutorialhq.com"); System.out.println("Contents of buffer:" + sb); // get the string from buffer from index 5 to index 8 int start = 5; int end = 8; String str = sb.substring(start,end); System.out.println("Results:"+str); } }
🌐
University of Texas
cs.utexas.edu › ~mitra › csSummer2012 › cs312 › lectures › strings.html
String and StringBuffer
int indexOf ( String str, int fromIndex ) : returns the first occurrence of the substring starting from the fromIndex.
🌐
javaspring
javaspring.net › java_lang › java_lang_stringbuffer_substring_method_a_comprehensive_guide
Java.lang.StringBuffer.substring() Method: A Comprehensive Guide — javaspring.net
The StringBuffer class in Java represents a mutable sequence of characters. The substring() method of the StringBuffer class is used to create a new String object that contains a substring of the characters in the StringBuffer.
🌐
Java Guides
javaguides.net › 2024 › 06 › java-stringbuffer-substring-method.html
Java StringBuffer substring() Method
June 10, 2024 - The StringBuffer.substring() method in Java provides a way to extract a substring from a StringBuffer object and return it as a new String. By understanding how to use this method, you can efficiently work with specific portions of the character ...
🌐
Android Developers
developer.android.com › api reference › stringbuffer
StringBuffer | API reference | Android Developers
Skip to main content · English · Deutsch · Español – América Latina · Français · Indonesia · Polski · Português – Brasil · Tiếng Việt · 中文 – 简体
🌐
University of Washington
courses.cs.washington.edu › courses › cse341 › 98au › java › jdk1.2beta4 › docs › api › java › lang › StringBuffer.html
Class java.lang.StringBuffer
Removes the characters in a substring of this StringBuffer. 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.
🌐
Oracle
docs.oracle.com › javase › 6 › docs › api › java › lang › StringBuffer.html
StringBuffer (Java Platform SE 6)
public StringBuffer delete(int start, int end) Removes the characters in a substring of this sequence. 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 exists. If start is equal to end, no changes are made.
🌐
Oracle
docs.oracle.com › en › java › javase › 11 › docs › api › java.base › java › lang › StringBuffer.html
StringBuffer (Java SE 11 & JDK 11 )
January 20, 2026 - public StringBuffer delete​(int start, int end) Removes the characters in a substring of this sequence. 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 exists. If start is equal to end, no changes ...
🌐
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
🌐
Oracle
docs.oracle.com › en › java › javase › 23 › docs › api › java.base › java › lang › StringBuffer.html
StringBuffer (Java SE 23 & JDK 23)
October 17, 2024 - Compares two StringBuffer instances lexicographically. ... Removes the characters in a substring of this sequence.