Java - String Buffer reverse() Method


Advertisements


Description

This method reverses the value of the StringBuffer object that invoked the method.

Let n be the length of the old character sequence, the one contained in the string buffer just prior to the execution of the reverse method. Then, the character at index k in the new character sequence is equal to the character at index n-k-1 in the old character sequence.

Syntax

Here is the syntax for this method −

public StringBuffer reverse()

Parameters

Here is the detail of parameters −

  • NA

Return Value

  • This method returns StringBuffer object with the reversed sequence.

Example

Live Demo
public class Test {

   public static void main(String args[]) {
      StringBuffer buffer = new StringBuffer("Game Plan");
      buffer.reverse();
      System.out.println(buffer);
   }  
}

This will produce the following result −

Output

nalP emaG

java_strings.htm

Advertisements