- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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 to reverse a given string in Java?
StringBuffer class provides you a method named reverse() to reverse its contents. One way to reverse a String is to append it to the StringBuffer object reverse it and convert it back to String.
Example
public class ReverseString { 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
- Reverse words in a given String in Java
- How to reverse String in Java?
- Java Program to Reverse a String
- How can I reverse a string in Java?
- How to reverse a string using lambda expression in Java?
- Reverse words in a given String in Python
- Reverse words in a given String in C#
- Java Program to reverse a given String with preserving the position of space.
- Write program to reverse a String without using reverse() method in Java?
- 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 to quickly reverse a string in C++?
- How to reverse a string in Python program?

Advertisements