- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java String substring() Method example.
The substring(int beginIndex, int endIndex) method of the String class. It returns a new string that is a substring of this string. The substring begins at the specified beginIndex and extends to the character at index endIndex - 1. Thus the length of the substring is endIndex-beginIndex.
Example
import java.lang.*; public class StringDemo { public static void main(String[] args) { String str = "This is tutorials point"; String substr = ""; // prints the substring after index 8 till index 17 substr = str.substring(8, 17); System.out.println("substring = " + substr); // prints the substring after index 0 till index 8 substr = str.substring(0, 8); System.out.println("substring = " + substr); } }
Output
substring = tutorials substring = This is
- Related Articles
- Java substring() method example.
- Java String compareTo() Method example.
- Java String endsWith() method example.
- Java String equals() method example.
- Java String equalsIgnoreCase() method example.
- Java String format() method example.
- Java String getBytes() method example.
- Java String getChars() method example.
- Java String indexOf() method example.
- Java String intern() method example.
- Java String isEmpty() method example.
- Java String lastIndexOf() method example.
- Java String length() method example.
- Java String replace() method example.
- Java String split() method example.

Advertisements