- 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
How can I reverse a string in Java?
The StringBuffer class has a method named reverse() which will reverse the contents of the current buffer. The program buffers the input String using StringBuffer (String string) method, reverse the buffer and then converts the buffer into a String with the help of toString() method.
Example
public class Sample { public static void main(String args[]){ String str = new String("Hello how are you"); StringBuffer sb = new StringBuffer(str); String str2 = sb.reverse().toString(); System.out.println(str2); } }
Output
uoy era woh olleH
- Related Articles
- How I can reverse a Java Array?
- How to reverse a given string in Java?
- How to reverse String in Java?
- How to reverse a string using lambda expression in Java?
- Java Program to Reverse a String
- Reverse words in a given String in Java
- Write program to reverse a String without using reverse() method in Java?
- How do I reverse an int array in Java
- How can we reverse a MySQL string connected by the dash?
- How to reverse a string in Python?
- Java program to reverse a string using recursion
- Java Program to Reverse a String Using Stacks
- Write a java program to reverse each word in string?
- How can I eliminate numbers in a string in Python?
- How to quickly reverse a string in C++?

Advertisements