- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Reverse the sequence of characters in a StringBuffer Object in Java
In order to reverse the sequence of characters in a StringBuffer Object, we use the reverse() method. The reverse() method replaces the character sequence with the reverse of its own.
Declaration − The java.lang.StringBuffer.reverse method is declared as follows−
public StringBuffer reverse()
Let us see a program to reverse the sequence of characters in a StringBuffer Object using the reverse() method.
Example
public class Example { public static void main(String[] args) { StringBuffer sb = new StringBuffer("Hello World"); System.out.println("Original StringBuffer Object: " + sb); sb.reverse(); System.out.println("New StringBuffer Object: " +sb); } }
Output
Original StringBuffer Object: Hello World New StringBuffer Object: dlroW olleH
Let us understand the above program. We created a StringBuffer Object
StringBuffer sb = new StringBuffer("Hello World");
After that we used the reverse() method to reverse the StringBuffer Object
sb.reverse();
- Related Articles
- Remove characters in a range from a Java StringBuffer Object
- Get the length of a StringBuffer Object in Java
- Change the length of the StringBuffer Object in Java
- Get the capacity of the StringBuffer Object in Java
- Change the default capacity of the StringBuffer Object in Java
- Change a single character in a Java StringBuffer object in Java
- Set the capacity value for a StringBuffer object in Java
- What is the difference between a String object and a StringBuffer object in java?
- Remove a character from a Java StringBuffer object
- Call append() method to construct a StringBuffer object in Java
- Create a StringBuffer object using a reference stored in a variable of type String in Java
- Constructors of StringBuffer class in Java.
- Methods of StringBuffer class in Java.
- Is StringBuffer final in Java?
- Sorting collection of String and StringBuffer in Java

Advertisements