You are here:   HomeJava ProgrammingJava ArrayGetting Length of an Array in Java
by Dinesh Thakur Category: array

String substring (int beginIndex) : This method returns a substring of the invoking StringBuffer. The substring returned contains a copy of characters beginning from the specified index position beginIndex and extends to the end of the string. For example, s1. substring (3) returns the substring lo Java.

String substring (int beginIndex, int endIndex) : This method is another version of previous method. It also returns a substring that begins at the specified index begin Index and extends to the character at the index endIndex-l. For example, the statement s1.substring (3, 6); returns the substring "lo". One should always specify the valid index range.

public class StringBufferSubstring

        public static void main(String[] args)
            StringBuffer sl = new StringBuffer("Hello Java");
            System.out.println("sl.substring(3) =" + sl.substring(3));
            System.out.println("sl.substring(3,6)=" + sl.substring(3,6));           

StringBuffer substring() Java Example