java.lang.StringBuffer reverse()


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 “” as initial contents of the string buffer. Then we use the reverse method to actually reverse the contents of the character sequence.


 * 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("");
		System.out.println("Contents of buffer:" + sb);
		//reverse the character sequence
		System.out.println("New contents of string buffer:" + sb);


Sample Output :

Running the above example source code will give the following output

reverse() method example

reverse() method example

Suggested Reading List :

References :