There are two overloaded methods for substring.
Method Signature:
1 2 3 |
public String substring(int startIndex) |
1 2 3 |
public String substring(int startIndex, int endIndex) |
String’s index always starts with 0. In case of substring method, startIndex is always inclusive and endIndex is exclusive
String substring Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
package org.arpit.java2blog; public class StringSubStringExample { public static void main(String[] args) { String str1= "java2blog.com"; // using beginIndex System.out.println(str1.substring(5)); // using beginIndex and endIndex System.out.println(str1.substring(5,9)); } } |
1 2 3 4 |
blog.com blog |