🌐
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 Server Java Syllabus Java Study Plan Java Interview Q&A Java Certificate ... The substring() method returns a substring from the string.
🌐
GeeksforGeeks
geeksforgeeks.org › java › stringbuilder-substring-method-in-java-with-examples
StringBuilder substring() method in Java with examples - GeeksforGeeks
December 19, 2025 - The extracted substring "For" is returned as a new String, and the original StringBuilder sb remains unchanged. Passing a negative index or an index greater than the length of the StringBuilder causes a StringIndexOutOfBoundsException at runtime. ... class GFG{ public static void main(String[] args){ StringBuilder sb = new StringBuilder("JavaDeveloper"); try { sb.substring(-3); } catch (Exception e) { System.out.println(e); } } }
🌐
Reddit
reddit.com › r/learnprogramming › [java] best practice to obtain substring using index of a character that may not be in original string.
r/learnprogramming on Reddit: [JAVA] Best practice to obtain substring using index of a character that may not be in original string.
April 10, 2015 -

I am provided a string. This string is a comma separated list of IDs. The list could have one ID, or it could have 1000 IDs (or any number of IDs). I need to determine how many characters the first ID is, whether it's alone or the first of many.

Currently I have a substring that uses indexOf as the end index, and uses the index of a comma. If there is no comma then the damn thing blows up. I have an OR clause that basically says "If this string up to the first comma is 5 digits OR the entire string is 5 digits, then do something".

I thought this would take care of the scenario with no comma. It doesn't. What is the best way to handle this?

EDIT I would share the code, but this is a massive application for work, and I'm guessing I'd get fired for sharing it, and according to the rules of this sub can't share code that isn't runnable. So while I REALLY think the one line I'm having issue with will help illustrate my problem very well, according to the sub rules I can't share it.

🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › String.html
String (Java Platform SE 8 )
October 20, 2025 - The class String includes methods ... 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 ...
🌐
Codedamn
codedamn.com › news › java
substring Method in Java (with examples)
October 15, 2022 - Say you have passed your username ... the value be changed. substring() method is a part of the Java String class and returns part of the 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?

🌐
DataFlair
data-flair.training › blogs › java-string-substring-method
Java String substring() Method with Examples - DataFlair
December 1, 2025 - The substring() method of the Java String class is a commonly used string manipulation method. It allows extracting a substring from a larger string by specifying the beginning and ending indices.
🌐
Baeldung
baeldung.com › home › java › java string › java string.substring()
Java.String.substring() | Baeldung
April 11, 2025 - @Test(expected = IndexOutOfBoundsException.class) public void whenSecondIndexEqualToLengthOfString_thenCorrect() { String s = "Welcome to Baeldung"; String sub = s.substring(0, 20); }
Find elsewhere
🌐
Spiceworks
community.spiceworks.com › programming & development
How to retrieve a substring from a string in JSP using java code - Programming & Development - Spiceworks Community
April 23, 2008 - I have a value of string stored in my recordset object as <% =rs.getString(“column”);%>. I need to check for a character in the resultset value and return as two separate strings. For example if my rs.getString(“column”)…
🌐
Vultr Docs
docs.vultr.com › java › standard-library › java › lang › String › contains
Java String contains() - Check If Contains Substring | Vultr Docs
November 19, 2024 - The contains() method in the Java String class is an indispensable tool for checking the presence of substrings within another string. It offers a straightforward, readable approach to string search operations, essential in many programming contexts.
🌐
DevGenius
blog.devgenius.io › java-substring-a-comprehensive-guide-082192995d1e
Java Substring: A Comprehensive Guide | Dev Genius
June 27, 2025 - This article will explore Java’s ... No problem! Read the full article here. Enjoy! A substring is a sequence of characters derived from another string....
🌐
FavTutor
favtutor.com › blogs › java-substrings
Substring in Java (with examples)
November 5, 2023 - In Java, the substring is a powerful method that allows developers to extract subsets or parts of a string. By using the substring() method, you can create smaller strings from a bigger one without modifying the original 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.
🌐
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
🌐
Medium
medium.com › @manojsharmajtp2 › substring-in-java-unveiling-the-magic-of-string-slicing-2fdb6c419500
Substring in Java: Unveiling the Magic of String Slicing | by manoj sharma | Medium
December 17, 2023 - In Java, a substring is like a slice of your favorite pizza — it’s a piece of a larger string. Consider the following scenario: you have a word and want to focus on only a portion of it; here is where substrings come into play.
🌐
Code with Mosh
forum.codewithmosh.com › t › java-strings-substrings › 15036
Java Strings & Substrings - Code with Mosh Forum
September 9, 2022 - Can anyone pls help me to understand ... String A=sc.next(); String B=sc.next(); System.out.print(A.substring(0,1).toUpperCase()+ A.substring(1) + " "+B.substring(0,1).toUpperCase() + ......
🌐
Coderanch
coderanch.com › t › 497744 › java › Implementing-substring-method
Implementing substring method in my own way. (Beginning Java forum at Coderanch)
June 2, 2010 - Gopi Chand Maddula wrote:I am trying to code the functionality of substring method of String Class My intention is to substring the given string without using any predefined methods. I'm pretty sure that's impossible. Maybe you mean "without using any predefined methods other than toCharArray()".
🌐
IronPDF
ironpdf.com › ironpdf for java › ironpdf for java blog › java help › java substring method
Java Substring Method (How It Works For Developers)
November 18, 2025 - Java offers two main ways to do this: public String substring(int beginIndex): This method creates a new string starting from the beginIndex to the end of the original string.
🌐
Tutorialspoint
tutorialspoint.com › home › java › java string substring
Java String Substring
September 1, 2008 - The substring begins with the character at the specified index and extends to the end of this string or up to endIndex 1, if the second argument is given. ... The specified substring. import java.io.*; public class Test { public static void ...
🌐
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