🌐
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 - Explanation: In the above code example, we use the substring(int beginIndex) method and specify the start index which is 8 and it didn't specified the end index. So it will make substring from end of the given string and we get the substring as "Geeks". ... Example 2: Java program to extract a substring from specified start index to specified end index using substring(int beginIndex, int endIndex).
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
String.format() is 3x faster in Java 17
Glad to see some of the small enhancements we did in 17 get recognition. Not sure if this one matters, but String::format shows up in profiles every now and then so it felt reasonable to me to give it some TLC in between larger projects. More on reddit.com
🌐 r/java
41
298
October 30, 2021
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
Why does the substring method in the String class create a new object and return that memory address rather than the information itself or interning it into the String Pool and returning that memory address?
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/javahelp
11
9
September 27, 2022
People also ask

Can substring() be used in Java Streams?
Yes, you can use substring inside Java Streams while mapping elements. For instance, in a list of strings, you can apply .map(str -> str.substring(0, 3)) to extract substrings. This is useful for processing collections functionally and efficiently.
🌐
upgrad.com
upgrad.com › home › tutorials › software & tech › substring in java
Substring in Java – Syntax, Examples & Usage Explained
Can substring() return an empty string in Java?
Yes, if the beginIndex and endIndex are the same, substring returns an empty string. It doesn't throw an error because technically you're extracting zero characters. This is often used to validate input or split strings safely without causing exceptions.
🌐
upgrad.com
upgrad.com › home › tutorials › software & tech › substring in java
Substring in Java – Syntax, Examples & Usage Explained
How is substring() different from split() in Java?
substring() extracts a part of the string based on index positions. In contrast, split() breaks a string into an array using a delimiter like a comma or space. They serve different purposes but can be used together for complex string parsing.
🌐
upgrad.com
upgrad.com › home › tutorials › software & tech › substring in java
Substring in Java – Syntax, Examples & Usage Explained
🌐
Codecademy
codecademy.com › docs › java › strings › .substring()
Java | Strings | .substring() | Codecademy
April 28, 2025 - In this example, substring(0, 11) extracts characters from index 0 (inclusive) to index 11 (exclusive). Yes, string indexing in Java starts at 0, so the first character of a string is at index 0.
🌐
DigitalOcean
digitalocean.com › community › tutorials › java-string-substring
Master Java Substring Method: Examples, Syntax, and Use Cases | DigitalOcean
February 20, 2025 - This method always returns a new string, and the original string remains unchanged because String is immutable in Java. In this tutorial, we’ll cover its syntax, use cases, and potential pitfalls while providing practical examples and solutions to common errors. public String substring(int beginIndex) public String substring(int beginIndex, int endIndex)
🌐
Tutorialspoint
tutorialspoint.com › java › lang › string_substring_index.htm
Java.lang.String.substring() Method
package com.tutorialspoint; import ... String substr = ""; // prints the substring after index 7 till index 17 substr = str.substring(7, 17); System.out.println("substring = " ......
🌐
Oracle
docs.oracle.com › en › java › javase › 17 › docs › api › java.base › java › lang › String.html
String (Java SE 17 & JDK 17)
April 21, 2026 - Replaces the first substring of this string that matches the given regular expression with the given replacement. ... Resolves this instance as a ConstantDesc, the result of which is the instance itself.
🌐
IONOS
ionos.com › digital guide › websites › web development › java substrings
How to use the Java substring method - IONOS
January 6, 2025 - The method Java String.split() ... the string. The method substring() takes that one step further and returns only the part of the string that you define....
Find elsewhere
🌐
Hero Vired
herovired.com › learning-hub › blogs › java-substring
Substring in Java: How to Use the Function [Code Examples]
Suppose you have a string, for ... a substring technique with the help of this: ... The Java substring(begIndex, endIndex) process extracts a part of the given string....
🌐
Upgrad
upgrad.com › home › tutorials › software & tech › substring in java
Substring in Java – Syntax, Examples & Usage Explained
May 14, 2025 - The return type of the substring() method is always a String. The method returns a new string containing the specified character range. It does not modify the original string (since strings are immutable in Java).
🌐
Tutorialspoint
tutorialspoint.com › java › lang › string_substring.htm
Java - String substring() Method
Following is an example to show the use of substring() method in Java by finding the substring of the provided string. Here both the beginning and the ending of the string is passed as parameters − · package com.tutorialspoint; public class StringDemo { public static void main(String[] args) { String str = "This is tutorials point"; String substr = ""; // prints the substring after index 7 till index 17 substr = str.substring(7, 17); System.out.println("substring = " + substr); // prints the substring after index 0 till index 7 substr = str.substring(0, 7); System.out.println("substring = " + substr); } } Let us compile and run the program above, the output will be displayed as follows − ·
🌐
Programiz
programiz.com › java-programming › library › string › substring
Java String substring()
If the endIndex is not passed, the substring begins with the character at the specified index and extends to the end of the string ... class Main { public static void main(String[] args) { String str1 = "program"; // 1st character to the last character · System.out.println(str1.substring(0)); // program // 4th character to the last character System.out.println(str1.substring(3)); // gram } }
🌐
Javatpoint
javatpoint.com › java-string-substring
Java String substring()
Java String substring() method with method signature and examples of concat, compare, touppercase, tolowercase, trim, length, equals, split, string substring in java etc.
🌐
KooR
koor.fr › Java › API › java › lang › String › substring__int__int.wp
KooR.fr - Méthode java.lang.String.substring
Version documentée : Java SE 17 · public String substring( int beginIndex, int endIndex ); Cette méthode permet d'extraire une sous-chaîne de caractères à partir des positions spécifiées.
🌐
BeginnersBook
beginnersbook.com › 2013 › 12 › java-string-substring-method-example
Java String substring() Method with examples
Note: The method is called like this: substring(start + 1, end), here start index is +1 because, we want to get the substring after the delimiter position, however the end index is not +1 because end index is not inclusive in substring method. public class JavaExample{ public static void main(String[] args){ //given string String str = "Welcome to [BeginnersBook.com]"; //we would like to get the substring between '[' and ']' int start = str.indexOf("["); int end = str.indexOf("]"); String outStr = str.substring(start + 1, end); System.out.println(outStr); } }
🌐
Igmguru
igmguru.com › blog › substring-in-java
Java String substring() Method: A Complete Guide | igmGuru
March 30, 2026 - If the index values are out of range, Java throws a StringIndexOutOfBoundsException. The original string is not modified: a new string is returned. Java provides two types of substring() methods to extract parts of a string using indexes.
🌐
Simplilearn
simplilearn.com › home › resources › software development › all you should know about substring in java
All You Should Know About Substring in Java | Simplilearn
September 11, 2025 - A substring is a part of another string. It's a commonly used method in java. Explore this tutorial to get an in-depth idea about substring in java. Start now!
Address   5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
🌐
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.
🌐
CodeGym
codegym.cc › java blog › strings in java › substring in java
Java String substring()
Here you will find the explanation of how using these methods, find out how they work and get some beneficial examples. Substring in general is a contiguous sequence of characters inside the String.
Published   July 23, 2024
🌐
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 - In the realm of Java programming, the substring functionality stands as a powerful tool for manipulating and extracting portions of text data within strings.