Java – StringBuffer substring() Example, StringBuffer substring() program

StringBuffer character sequence can be return new string from sequence with the help of substring() method in java. substring() function get String from starting index and end of index number in character sequence of the StringBuffer. Return type of substring() is String. Use of String substring() in java is shown below.

Example of StringBuffer substring() in java, JSP

public class StringBufferSubStringExample {

    public static void main(String[] args) {

        StringBuffer sb = new StringBuffer("Java StringBuffer substring");

        System.out.println("Output :"+sb);

        String str1=sb.substring(3); // starting index

        System.out.println("Output :"+str1);

        String str2=sb.substring(2,11); //starting index, ending index 

        System.out.println("Output :"+str2);
    }
}

Output

Output :Java StringBuffer substring
Output :a StringBuffer substring
Output :va String

Tags:

Bookmark  

 

Leave a Reply

Security Code:

 

  Random Post