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

StringBuffer character sequence can be replaced with the help of replace() method in java. replace() function replace the occurrence of string literal found in the String from starting index and end of index number in character sequence of the StringBuffer. Use of String replace() in java is shown below.

Example of StringBuffer replace() in java, JSP

public class StringBufferReplaceExample {

    public static void main(String[] args) {

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

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

        sb.replace(5, 8, "replace");

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

Output

Output :Java abc StringBuffer
Output :Java replace StringBuffer

Tags: ,

Bookmark  

 

Leave a Reply

Security Code:

 

  Random Post