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).
Java Substring
01:11
How can you get a substring from a String? Cracking the Java Coding ...
02:06
Java String Methods Explained: length(), charAt(), substring() ...
03:12
#69 Java String contains() Method – Check if a String Has a ...
05:32
Java Strings - substring() - YouTube
08:05
Java substrings are easy! 📧 - YouTube
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.
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)
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.
Address: 5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
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.