It's supposed to be an efficiency measure. i.e. when you're taking a substring you won't create a new char array, but merely create a window onto the existing char array.

Is this worthwhile ? Maybe. The downside is that it causes some confusion (e.g. see this SO question), plus each String object needs to carry the offset info into the array, even if it's not used.

EDIT: This behaviour has now changed as of Java 7. See the linked answer for more info

Answer from Brian Agnew on Stack Overflow
🌐
W3Schools
w3schools.com › java › ref_string_substring.asp
Java String substring() Method
Java Examples Java Videos Java Compiler Java Exercises Java Quiz Java Code Challenges Java Practice Problems Java Server Java Syllabus Java Study Plan Java Interview Q&A ... The substring() method returns a substring from the string.
🌐
GeeksforGeeks
geeksforgeeks.org › java › substring-in-java
Java String substring() Method - GeeksforGeeks
April 11, 2025 - In Java, the substring() method of the String class returns a substring from the given string.
Discussions

What does String.substring exactly do in Java? - Stack Overflow
I always thought if I do String s = "Hello World".substring(0, 5), then I just get a new string s = "Hello". This is also documented in the Java API doc: "Returns a new string that is a substring o... More on stackoverflow.com
🌐 stackoverflow.com
How to correctly use the substring method? (Java)
You are deeply confused about how substring() works - it's a method of String, and it does not take Strings as parameters. See here for an example. More on reddit.com
🌐 r/learnprogramming
5
5
February 2, 2013
Get Substring from a String in Java - Stack Overflow
I have the following text: ...,Niedersachsen,NOT IN CHARGE SINCE: 03.2009, CATEGORY:..., Now I want to extract the date after NOT IN CHARGE SINCE: until the comma. So i need only 03.2009 as resul... More on stackoverflow.com
🌐 stackoverflow.com
What is the purpose of a substring of Java programming? Discuss its function by using one example.
Provide the details of the Java substring method. What is its role in extracting parts of the strings? Dive into the various scenarios for string manipulat... More on janbasktraining.com
🌐 janbasktraining.com
1
November 3, 2023
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › String.html
String (Java Platform SE 8 )
July 21, 2026 - The class String includes methods for examining individual characters of the sequence, for comparing strings, for searching strings, for extracting substrings, and for creating a copy of a string with all characters translated to uppercase or to lowercase. Case mapping is based on the Unicode Standard version specified by the Character class. The Java language provides special support for the string concatenation operator ( + ), and for conversion of other objects to strings.
🌐
CodeGym
codegym.cc › java blog › strings in java › substring in java
Java String substring()
July 23, 2024 - Java Substring in general is a contiguous sequence of characters inside the String. It could be a part of the String or the whole String as well. What is substring in Java? This language has a substring() method, or rather two methods, thanks ...
🌐
TechVidvan
techvidvan.com › tutorials › java-string-substring
Java String substring() - TechVidvan
December 2, 2025 - A portion of a string is returned by the Java String class substring(). We pass beginIndex and endIndex number position in the Java substring method where beginIndex is inclusive, and endIndex is exclusive.
🌐
Codecademy
codecademy.com › docs › java › strings › .substring()
Java | Strings | .substring() | Codecademy
April 28, 2025 - The .substring() method in Java returns a portion of a string from a specified starting index to an (optional) ending index.
Find elsewhere
🌐
Medium
maheshjtp.medium.com › what-is-a-substring-in-java-syntax-applications-of-java-substring-9abbf79350e9
What is a Substring in Java? Syntax/ Applications of Java Substring | by Mahesh Sharma | Medium
March 7, 2025 - Optimize performance by minimizing unnecessary substring operations within loops or recursive functions. ... Java substring is a versatile and indispensable feature for working with text data in Java applications.
🌐
HappyCoders
happycoders.eu › home › java › java substring() method: how to use it and how it works
Java substring() Method: How to Use It and How It Works
4 weeks ago - Ultimately, the JDK developers weighed the pros and cons of the previous solution and decided to change the implementation in Java 7 Update 6: since then, char arrays are no longer shared between strings; instead, the substring() method (or the String constructor it calls) creates a copy of the requested section of the char array.
🌐
The Renegade Coder
therenegadecoder.com › code › be-careful-with-strings-substring-method-in-java
Be Careful with String’s Substring Method in Java – The Renegade Coder
May 26, 2020 - Returns a new string that is a substring of this string. The substring begins at the specified beginIndex and extends to the character at index endIndex - 1. Thus the length of the substring is endIndex-beginIndex. Java API, 2019
🌐
IONOS
ionos.com › digital guide › websites › web development › java substrings
How to use the Java substring method - IONOS
January 6, 2025 - Java’s substring method is used to extract a substring from a larger string. There are two different ways to use it, either sep­a­rat­ing the string from an index to the end or with a pre-defined beginning and ending index for the substring.
🌐
Reddit
reddit.com › r/learnprogramming › how to correctly use the substring method? (java)
r/learnprogramming on Reddit: How to correctly use the substring method? (Java)
February 2, 2013 -

Hey guys, I've been working on this Java homework for my class and this whole section about string manipulation is confusing me.

The homework asks to add statements that use the substring method to get the first half and second half of phrase.

I'm assuming that means using the substring method, but I always get errors trying to compile what I put in. So here's the code. I'm not exactly sure how to use the substring method in the way they ask, and my book doesn't really go over it well. Should I be creating another variable or just use what I have?

🌐
DevGenius
blog.devgenius.io › java-substring-a-comprehensive-guide-082192995d1e
Java Substring Failed When Input Changed Shape | Dev Genius
July 6, 2026 - Java’s String class provides two overloaded substring methods: substring(int beginIndex) – Extracts a substring from the specified beginIndex to the end of the string.
🌐
Baeldung
baeldung.com › home › java › java string › get substring from string in java
Get Substring from String in Java | Baeldung
July 21, 2024 - Regular expressions will come to our rescue if we have to extract a substring that matches a specific pattern. In the example String, Julia’s date of birth is in the format “dd-mm-yyyy”. We can match this pattern using the Java regular expression API.
🌐
DigitalOcean
digitalocean.com › community › tutorials › java-string-substring
Master Java Substring Method: Examples, Syntax, and Use Cases | DigitalOcean
February 20, 2025 - Learn how to use the Java substring method. Explore syntax, practical examples, and common errors to handle substrings effectively.
🌐
Secondspace
backup.secondspace.no › news › java-string-substring
Java String Substring - Secondspace
April 16, 2026 - The substring() method in Java retrieves a portion of a string based on provided start and end indices. It returns a new string containing characters from the original, from the given start index (inclusive) up to—but not including—end index.
🌐
Netjstech
netjstech.com › 2016 › 07 › string-charat-and-substring-methods-in-java.html
Java String substring() Method - Getting Substring | Tech Tutorials
Note that CharSequence is an interface which is implemented by String, StringBuffer, StringBuilder classes. 1. Using substring method to get substring of a string by specifying only beginIndex or by specifying both beginIndex and endIndex.
🌐
Tutorialspoint
tutorialspoint.com › java › lang › string_substring.htm
Java - String substring() Method
The Java String substring() method is used to retrieve a substring of a String object. The substring starts with the character at the given index and continues to the end of the current string.
🌐
JanBask Training
janbasktraining.com › community › java › what is the purpose of a substring of java programming? discuss its function by using one example.
What is the purpose of a substring of Java programming? Discuss its function by using one example. | JanBask Training Community
November 3, 2023 - Java substring is a method in Java programs, which is used for extracting the portions of string based on the provided indices. It includes passing the starting index as the first argument while the ending index is considered as the second argument.