Java Tutorial

Java Control Statements

Object Oriented Programming

Java Built-in Classes

Java File Handling

Java Error & Exceptions

Java Multithreading

Java Synchronization

Java Networking

Java Collections

Java List Interface

Java Queue Interface

Java Map Interface

Java Set Interface

Java Data Structures

Java Collections Algorithms

Java Miscellaneous

Advanced Java

Java APIs & Frameworks

Java Useful Resources

Java - String Buffer reverse() Method



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

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