- 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
Write a java program to reverse each word in string?
StringBuffer class of the java.lang package provides reverse() method. This method returns a reverse sequence of the characters in the current String. Using this method you can reverse a string in Java.
To reverse each word in a string you need to split the string, store it in an array of strings and reverse each word using the reverse() method of the StringBuffer class.
Example
import java.lang.*; public class StringBufferDemo { public static void main(String[] args) { StringBuffer buff = new StringBuffer("tutorials point"); System.out.println("buffer = " + buff); // reverse characters of the buffer and prints it System.out.println("reverse = " + buff.reverse()); // reverse of the buffer is equivalent to the actual buffer buff = new StringBuffer("malyalam"); System.out.println("buffer = " + buff); // reverse characters of the buffer and prints it System.out.println("reverse = " + buff.reverse()); } }
Output
buffer = tutorials point reverse = tniop slairotut buffer = malyalam reverse = malaylam
- Related Articles
- Write a java program reverse tOGGLE each word in the string?
- Write a java program to tOGGLE each word in string?
- Java program to reverse each word in a sentence
- Write a Java program to capitalize each word in the string?
- Write program to reverse a String without using reverse() method in Java?
- Python program to reverse each word in a sentence?
- Program to reverse the position of each word of a given string in Python
- Write a Golang program to reverse a string
- Java Program to Reverse a String
- Java Program to Capitalize the first character of each word in a String
- Write a program to reverse an array or string in C++
- Java program to reverse a string using recursion
- Java Program to Reverse a String Using Stacks
- Write a python program to count occurrences of a word in string?
- Find frequency of each word in a string in Java

Advertisements