🌐
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

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
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
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
[JAVA] Substring method question about indexing.
Index 0 does refer to R. The range of the substring method is [beginIndex, endIndex). So what you have says to start at the beginning, then include only things before the first character, which is nothing, so you get an empty string. If you want just the first character you need substring(0, 1). It may be easier to think of if you consider the parameters to be beginIndex and beginIndex + substringLength. More on reddit.com
🌐 r/learnprogramming
2
1
April 11, 2013
🌐
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.
🌐
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 = " ......
🌐
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.
🌐
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
🌐
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 − ·
🌐
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); } }
🌐
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....
🌐
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?

🌐
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.
🌐
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.
🌐
DevGenius
blog.devgenius.io › java-substring-a-comprehensive-guide-082192995d1e
Java Substring: A Comprehensive Guide - DevGenius.io
June 27, 2025 - 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.
🌐
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.
🌐
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
🌐
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
🌐
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 } }
🌐
Baeldung
baeldung.com › home › java › java string › get substring from string in java
Get Substring from String in Java | Baeldung
July 21, 2024 - For more details on the Java regular expressions check out this tutorial. We can use the split method from the String class to extract a substring. Say we want to extract the first sentence from the example String.