Java.lang.StringBuffer.reverse() Method


Advertisements


Description

The java.lang.StringBuffer.reverse() method causes this character sequence to be replaced by the reverse of the sequence.

Declaration

Following is the declaration for java.lang.StringBuffer.reverse() method

public StringBuffer reverse()

Parameters

NA

Return Value

This method returns a reference to this object.

Exception

NA

Example

The following example shows the usage of java.lang.StringBuffer.reverse() method.

package com.tutorialspoint;

import java.lang.*;

public class StringBufferDemo {

   public static void main(String[] args) {
  
      StringBuffer buff = new StringBuffer("tutorials point");
      System.out.println("buffer = " + buff);

      // reverse characters of the buffer and prints it
      System.out.println("reverse = " + buff.reverse());
  
      // reverse of the buffer is equivalent to the actual buffer
      buff = new StringBuffer("malyalam");
      System.out.println("buffer = " + buff);
	
      // reverse characters of the buffer and prints it
      System.out.println("reverse = " + buff.reverse());
   }
}

Let us compile and run the above program, this will produce the following result −

buffer = tutorials point
reverse = tniop slairotut
buffer = malayalam
reverse = malayalam

java_lang_stringbuffer.htm

Advertisements