🌐
GeeksforGeeks
geeksforgeeks.org › java › substring-in-java
Java String substring() Method - GeeksforGeeks
April 11, 2025 - Note: If we pass the start index and endIndex with the same value so it will return an empty substring (""). Example 1: Java program to extract a substring using substring(int beginIndex).
🌐
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.
🌐
Codecademy
codecademy.com › docs › java › strings › .substring()
Java | Strings | .substring() | Codecademy
April 28, 2025 - This example demonstrates how to extract a substring using substring(beginIndex) method, starting from a specific index to the end of the string: ... Original string: Hello, Java!
🌐
BeginnersBook
beginnersbook.com › 2013 › 12 › java-string-substring-method-example
Java String substring() Method with examples
Examples: “hamburger”.substring(4, 8) returns “urge” “smiles”.substring(1, 5) returns “mile” Parameters: beginIndex – the beginning index, inclusive. endIndex – the ending index, exclusive. Returns: the specified substring. Throws: IndexOutOfBoundsException – if the beginIndex ...
🌐
DigitalOcean
digitalocean.com › community › tutorials › java-string-substring
Master Java Substring Method: Examples, Syntax, and Use Cases | DigitalOcean
Learn how to use the Java substring method. Explore syntax, practical examples, and common errors to handle substrings effectively.
🌐
Programiz
programiz.com › java-programming › library › string › substring
Java String substring()
Working of Java String substring() ... is greater than endIndex · class Main { public static void main(String[] args) { String str1 = "program"; // 1st character to the last character ·...
🌐
Scientech Easy
scientecheasy.com › home › blog › substring in java (with example)
Substring in Java (with Example) - Scientech Easy
May 29, 2025 - They are as follows: 1. public String substring(int startIndex): This method returns a new string that is a substring of this string. Here, startIndex represents the index at which the substring begins with a character.
🌐
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 - Let’s illustrate the usage of ... = “Java is amazing!”; // Extract substring from index 5 to the end String substring1 = originalString.substring(5); System.out.println(“Substring 1: “ + substring1); // Extract ...
🌐
Baeldung
baeldung.com › home › java › java string › java string.substring()
Java.String.substring() | Baeldung
April 11, 2025 - @Test public void whenCallSubstring_thenCorrect() { String s = "Welcome to Baeldung"; assertEquals("Welcome", s.substring(0, 7)); }
Find elsewhere
🌐
IONOS
ionos.com › digital guide › websites › web development › java substrings
How to use the Java substring method - IONOS
January 6, 2025 - The last four digits are: 1142java · The second way to use Java’s substring() method allows for more control over the resulting substring. You’ll not only specify the starting point of the substring but also an end point. The syntax looks as follows: String substring(int beginIndex, int endIndex)java · The beginIndex is inclusive, and the endIndex is exclusive. Let’s once again look at a simple example: public class Main { public static void main(String args[]) { String Str = new String("This is an example.
🌐
TechVidvan
techvidvan.com › tutorials › java-string-substring
Java String substring() - TechVidvan
December 2, 2025 - A portion of a string is returned ... is inclusive, and endIndex is exclusive. For example, the initial index begins at 0 while the end index begins at 1....
🌐
Software Testing Help
softwaretestinghelp.com › home › java › java substring() method – tutorial with examples
Java substring() Method - Tutorial With Examples
April 1, 2025 - 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.
🌐
Upgrad
upgrad.com › home › tutorials › software & tech › substring in java
Substring in Java – Syntax, Examples & Usage Explained
May 14, 2025 - Think of it like cutting a slice out of a loaf of bread — you specify the starting and (optionally) ending slice. String str = "JavaProgramming"; String sub = str.substring(0, 4); System.out.println(sub);
🌐
Java67
java67.com › 2016 › 01 › 5-examples-of-substring-in-java.html
5 Examples of substring() in Java | Java67
public String substring(int beginIndex) public String substring(int beginIndex, int endIndex) In the case of the first method, substring starts with beginIndex and goes till the end of String, while, in the case of an overloaded method, substring starts from beginIndex and goes till endIndex -1. Since String in Java is zero indexes based, beginIndex can be from 0 to length of String. Let's see a couple of examples of substring methods to learn how they work:
🌐
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.
🌐
Home and Learn
homeandlearn.co.uk › java › substring.html
java for complete beginners - substring
We want to start at the first character after the space (space + 1), and end two characters after this position, which is (spacePos + 1) + 2. Add the following lines to your code (The ones highlighted. Our new substring method spills over on to two lines, but you can keep your on one, if you ...
🌐
Tutorialspoint
tutorialspoint.com › java › lang › string_substring.htm
Java - String substring() Method
The Java String substring() method is used to retrieve a substring of a String object. The substring starts with the character at the given index and continues to the end of the current string.
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › java.lang.string.substring
String.Substring Method (Java.Lang) | Microsoft Learn
Examples: <blockquote> "hamburger".substring(4, 8) returns "urge" "smiles".substring(1, 5) returns "mile" </blockquote> Java documentation for java.lang.String.substring(int, int).
🌐
How to do in Java
howtodoinjava.com › home › string › java string substring()
Java String substring() with Examples - HowToDoInJava
January 10, 2023 - Assertions.assertThrows(IndexOutOfBoundsException.class, () -> { //invalid index str.substring(-1); }); Assertions.assertThrows(IndexOutOfBoundsException.class, () -> { //begin index > end index str.substring(6, 4); }); In this short Java tutorial, we learned to get the substring of a specified string using the begin and end indices.
🌐
Vultr Docs
docs.vultr.com › java › standard-library › java › lang › String › substring
Java String substring() - Extract Substring | Vultr Docs
January 1, 2025 - Looping over a string to extract multiple substrings is a common use case, for example, parsing a formatted data string: Consider a scenario where you want to extract words separately from a string containing space-separated words: ... String sentence = "Java substring method"; String[] words = sentence.split(" "); for(String word : words) { System.out.println(word); } Explain Code