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).
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
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
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
[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
Videos
08:05
Java substrings are easy! 📧 - YouTube
substring And length (Java String Methods) - YouTube
03:31
substring method in java | substring in Java example | String ...
How does Java's substring method work? #java #computerscience #apcsa ...
05:42
Explain substring() method of String Class in Java (Core Java ...
05:13
Substrings in Java - YouTube
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 = " ......
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); } }
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?
Top answer 1 of 3
5
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.
2 of 3
3
Yeah, this is completely wrong.... Java is an object oriented programming language, meaning that unless u specifically say that a method or variable is static, you must provide an implicite parameter (an object). The substring method is not static so u must supply a string object to it. In this case, supply the phrase variable. The substring method returns a string value of the characters between two indexes, inclusive. You should write.... firstHalf = phrase.substring(0,middleIndex); This will return the characters between index 0 and the middle index of phrase to the String object firstHalf. I hope that helped a little.
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.
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 } }