

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 Questions & Answers
- How I can reverse a Java Array?
- How to reverse a given string in Java?
- How to reverse String in Java?
- Java Program to Reverse a String
- Reverse words in a given String in Java
- How to reverse a string using lambda expression in Java?
- How do I reverse an int array in Java
- Write program to reverse a String without using reverse() method in Java?
- How can we reverse a MySQL string connected by the dash?
- How to reverse a string in Python?
- How can I eliminate numbers in a string in Python?
- Reverse a string in C#
- Java program to reverse a string using recursion
- Java Program to Reverse a String Using Stacks
- How can I convert a Python tuple to string?
Advertisements