java.lang.StringBuffer reverse()
Syntax:
public StringBuffer reverse()
Java Code Example :
This java example source code demonstrates the use of reverse() method of StringBuffer class. Initially the code assigns a string “javatutorialhq.com” as initial contents of the string buffer. Then we use the reverse method to actually reverse the contents of the character sequence.
package com.javatutorialhq.java.examples;
/*
* This example source code demonstrates the use of
* reverse() method of StringBuffer class
*/
public class StringBufferReverse {
public static void main(String[] args) {
// initialize the StringBuffer object
StringBuffer sb = new StringBuffer("javatutorialhq.com");
System.out.println("Contents of buffer:" + sb);
//reverse the character sequence
sb.reverse();
System.out.println("New contents of string buffer:" + sb);
}
}
Sample Output :
Running the above example source code will give the following output
Suggested Reading List :
References :
