Java-Reverse and Replace

reverse

You can reverse the characters with in a StrngBuffer object using reverse() method. This method returns the reversed object.

replace

You can replace one set of characters with another set inside a StringBuffer object by calling replace(int startIndex, int endIndex, String str). The substring being replaced is specified by the indexes startIndex and endIndex. Thus, the substring at startIndex through endIndex is replaced. The replacement string is passed in str.

Program

0

Program Source

public class Javaapp {
    
    public static void main(String[] args) {
        
        StringBuffer str1 = new StringBuffer("Hajsofjavatutorial");
        str1.reverse();
        System.out.println(str1);
        
        StringBuffer str2 = new StringBuffer("HajsofCsharptutorial");
        str2.replace(6, 12, "java");
        System.out.println(str2);
    }
}

Leave a Comment