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

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Related Articles