Thursday, January 23, 2025
HomeProgrammingJava String Substring()

Java String Substring()

The substring() method in Java is used to extract a portion of a string. It is a part of the String class and comes in two variations:

  1. substring(int beginIndex): Returns a substring starting from the specified index to the end of the string.
  2. substring(int beginIndex, int endIndex): Returns a substring starting from beginIndex (inclusive) to endIndex (exclusive).
See also  Division operators in python

Example:

java
String str = "Hello, World!";
System.out.println(str.substring(7)); // Output: World!
System.out.println(str.substring(0, 5)); // Output: Hello

The method is useful for string manipulation and processing.

RELATED ARTICLES
0 0 votes
Article Rating

Leave a Reply

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
- Advertisment -

Most Popular

Recent Comments

0
Would love your thoughts, please comment.x
()
x