🌐
Software Testing Help
softwaretestinghelp.com › home › java › java substring() method – tutorial with examples
Java substring() Method - Tutorial With Examples
April 1, 2025 - Scenario 1: What will be the output of the substring method when the specified index is not present in the main String? Explanation: In this scenario, we are going to take an input String “Java Programming” and we will try to specify the index as 255 and 350 for the starting and ending indexes respectively.
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
🌐
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.
🌐
Java Code Geeks
examples.javacodegeeks.com › home › java development › core java › lang › string
String indexOf Java Example - Java Code Geeks
March 17, 2020 - ... The indexOf()(String or character target) method searches left-to-right inside the given string for a “target” string. The method returns the index number where the target string is first found or -1 if the target is not found.
🌐
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.
🌐
Java Code Geeks
examples.javacodegeeks.com › home › java development › java basics › string
Substring Java Example - Java Code Geeks
July 5, 2022 - In this post, we feature a comprehensive Substring Java Example. We will show how to use Java String substring() API method. ... This parameter is mandatory and it specifies the starting position of the extracted string. Note that first character of string is at index 0 not 1.
🌐
Upgrad
upgrad.com › home › tutorials › software & tech › substring in java
Substring in Java – Syntax, Examples & Usage Explained
August 21, 2026 - 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).
🌐
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. This method is most useful when you deal with text manipulation, parsing, or data extraction. This method either takes 1 parameter or 2 parameters, i.e., start and end value as arguments.
Find elsewhere
🌐
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.
🌐
YouTube
youtube.com › nelson darwin pak tech
how to split a string in java eclipse ide | split a string into its substrings in java eclipse ide - YouTube
In this tutorial you will learn1. how to split a string into its substrings in java eclipse.2. breaking a long string into its substrings in java in eclipse....
Published: October 17, 2022
Views: 237
🌐
Vultr Docs
docs.vultr.com › java › standard library › java › lang › string › substring()
Java String substring() - Extract Substring | Vultr Docs
January 1, 2025 - The substring() method in Java is a fundamental tool for string manipulation, allowing developers to extract specific parts of a string based on given index positions.
🌐
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 - 3. Deleting the first character : Strings in Java start at index 0, i.e., the first character is 0 indexed. If you need to remove the first character, use substring(1).
Address: 5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
🌐
BeginnersBook
beginnersbook.com › 2013 › 12 › java-string-substring-method-example
Java String substring() Method with examples
str.substring(1): This excludes first character as the index 0 character (first character) is excluded.
🌐
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 to Java method overloading.
🌐
Programiz
programiz.com › java-programming › library › string › substring
Java String substring() | Programiz
January 31, 2024 - System.out.println(str1.substring(0, 4)); } } // Output: java ... The substring() method can take a maximum of two arguments. ... The substring() method returns a substring from the given string. The substring begins with the character at the startIndex and extends to the character at index endIndex - 1
🌐
IONOS
ionos.com › digital guide › websites › web development › java substrings
How to use the Java substring method - IONOS
January 6, 2025 - If you want to extract a specific subset from the larger string, you have several options. The method Java String.split() breaks an entire string down into its in­di­vid­ual parts to, for example, give you a clearer overview of the string. The method substring() takes that one step further and returns only the part of the string that you define.
🌐
Igmguru
igmguru.com › home › blog › java › substring in java
Java String substring() Method: A Complete Guide
2 weeks ago - Java provides two types of substring() methods to extract parts of a string using indexes. Understanding these two variations helps in choosing the correct method for different string manipulation needs. This method returns part of a string starting from the given index to the end. It ignores all characters before the index and keeps everything after it. ... Index count: P(0) r(1) o(2) g(3)...
🌐
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
1 month ago - Two details were added: If a UTF-16 string contains a substring consisting only of Latin-1 characters, substring() creates that substring compactly, with one byte per character. And an empty section of a non-empty string is always the literal "". I wrote a small program to demonstrate the changes of the substring() method over the Java versions.