🌐
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).
🌐
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.
🌐
Programiz
programiz.com › java-programming › library › string › substring
Java String substring() | Programiz
January 31, 2024 - System.out.println(str1.substring(0)); // program // 4th character to the last character System.out.println(str1.substring(3)); // gram } } class Main { public static void main(String[] args) { String str1 = "program"; // 1st to the 7th character System.out.println(str1.substring(0, 7)); // program // 1st to the 5th character
🌐
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!
🌐
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.
🌐
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.
🌐
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.
🌐
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 ... 5 to the end String substring1 = originalString.substring(5); System.out.println(“Substring 1: “ + substring1); // Extract substring from index 0 to 4 (exclusive) String substring2 ...
Find elsewhere
🌐
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 is negative, or endIndex is larger than the length of this String object, or beginIndex is larger than endIndex. see: https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#substring(int, int)
🌐
Baeldung
baeldung.com › home › java › java string › get substring from string in java
Get Substring from String in Java | Baeldung
July 21, 2024 - In this quick tutorial, we’ll focus on the substring functionality of Strings in Java. We’ll mostly use the methods from the String class and few from Apache Commons’ StringUtils class. In all of the following examples, we’re going to using this simple String:
🌐
Edureka
edureka.co › blog › substring-in-java
Substring in Java | String substring() Method Example | Edureka
June 14, 2021 - This method has two variants and it returns a new string which is a substring of this string. The substring begins with a character at the specified index BeginIndex and extends to the end of the string or up to endIndex – 1 if another argument is present. ... Let’s work with an example.
🌐
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 - If the second argument is given, ... -1. Syntax : public String substring(int startIndex, int endIndex) Parameters: startIndex: the starting index, inclusive ... Return Value: Specified substring.
Address: 5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
🌐
DEV Community
dev.to › satyam_gupta_0d1ff2152dcc › master-java-substring-a-no-fluff-guide-with-examples-real-world-use-25e7
Master Java substring(): A No-Fluff Guide with Examples & Real-World Use - DEV Community
November 25, 2025 - The first character is at position 0, not 1. This trips up a lot of beginners, so keep it in mind! Syntax & Example java String originalString = "Hello, World!"; String subString = originalString.substring(7);
🌐
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.
🌐
Tutorial Gateway
tutorialgateway.org › java-substring-method
Java substring
August 9, 2026 - public String substring(int Starting_index); // It will return Integer //In order to use in program Str_Object.substring(int Startig_index) The following method will accept the integer value, the starting index position (Starting_index), where ...
🌐
Upgrad
upgrad.com › home › tutorials › software & tech › substring in java
Substring in Java – Syntax, Examples & Usage Explained
August 21, 2026 - 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);
🌐
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.
🌐
Tpoint Tech
tpointtech.com › substring-in-java
Substring in Java (With Examples) - Tpoint Tech
2 weeks ago - The following example demonstrates finding substring using the split() method. ... import java.util.*; public class Main { public static void main(String args[]) { String text = "Matthew Hayden is a cricket player."; String[] sentences = text.split(","); System.out.println(Arrays.toString(sentences)); } } Compile and Run
🌐
Home and Learn
homeandlearn.co.uk › java › substring.html
java for complete beginners - substring
One really useful method available to you is called substring. This method allows you to grab one chunk of text from another. In our email address programme above, for example, we could grab the last five characters from the address and see if it is co.uk.