GeeksforGeeks
geeksforgeeks.org › java › stringbuffer-reverse-method-in-java
StringBuffer reverse() Method in Java with Examples - GeeksforGeeks
August 4, 2022 - The Java.lang.StringBuffer.reverse() is an inbuilt method that is used to reverse the characters in the StringBuffer.
Tutorialspoint
tutorialspoint.com › java › lang › stringbuffer_reverse.htm
Java StringBuffer reverse() Method
The Java StringBuffer reverse() method is used to reverse the characters of a StringBuffer object. It replaces the sequence of characters in reverse order. The method is a static method with predefined logic for reversing a string in Java.
Tutorialspoint
tutorialspoint.com › java › stringbuffer_reverse.htm
Java - String Buffer reverse() Method
This method reverses the value of the StringBuffer object that invoked the method. Let n be the length of the old character sequence, the one contained in the string buffer just prior to the execution of the reverse method.
IncludeHelp
includehelp.com › java-programs › java-program-to-demonstrate-example-of-string-reverse.aspx
How to reverse a string in Java with and without using StringBuffer.reverse() method?
import java.util.*; public class ReverseString { public static void main(String args[]) { //declare string object and assign string StringBuffer str= new StringBuffer("Hello World!"); //reverse the string str.reverse(); //print the reversed string System.out.println("String after reversing:" + str); } }
Oracle
docs.oracle.com › javase › 7 › docs › api › java › lang › StringBuffer.html
StringBuffer (Java Platform SE 7 )
public StringBuffer reverse() Causes this character sequence to be replaced by the reverse of the sequence. If there are any surrogate pairs included in the sequence, these are treated as single characters for the reverse operation. Thus, the order of the high-low surrogates is never reversed.
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › StringBuffer.html
StringBuffer (Java Platform SE 8 )
April 21, 2026 - public StringBuffer reverse() Causes this character sequence to be replaced by the reverse of the sequence. If there are any surrogate pairs included in the sequence, these are treated as single characters for the reverse operation. Thus, the order of the high-low surrogates is never reversed.
Javatpoint
javatpoint.com › java-stringbuffer-reverse-method
Java StringBuffer reverse() Method with Examples - Javatpoint
Java StringBuffer reverse() Method with Examples on append(), capacity(), charAt(), delete(), indexOf(), getChars(), insert(), lastIndexOf(), length(), replace(), setCharAt(), setLength(), codePointAt(), codePointBefore(), codePointCount(), ensureCapacity() etc.
Java Tutorial HQ
javatutorialhq.com › java tutorial › java.lang › stringbuffer › reverse() method example
Java StringBuffer reverse() method example
September 30, 2019 - package com.javatutorialhq.java.examples; /* * This example source code demonstrates the use of * reverse() method of StringBuffer class */ public class StringBufferReverse { public static void main(String[] args) { // initialize the StringBuffer object StringBuffer sb = new StringBuffer("javatutorialhq.com"); System.out.println("Contents of buffer:" + sb); //reverse the character sequence sb.reverse(); System.out.println("New contents of string buffer:" + sb); } }
GeeksforGeeks
geeksforgeeks.org › java › reverse-a-string-in-java
Reverse a String in Java - GeeksforGeeks
Explanation: Characters are stored in a list and reversed using Collections.reverse(). This approach is helpful when you’re already working with Java collections. StringBuffer is similar to StringBuilder but thread-safe.
Published May 12, 2026
Wikitechy
wikitechy.com › tutorials › java › java-stringbuffer-reverse
java tutorial - Java StringBuffer reverse() method - By Microsoft Award MVP - tutorial java - java programming - learn java - java for beginners - Learn in 30sec | wikitechy
Java StringBuffer reverse() method — changes the value of the StringBuffer object that called the method.
Oracle
docs.oracle.com › en › java › javase › 15 › docs › api › java.base › java › lang › StringBuffer.html
StringBuffer (Java SE 15 & JDK 15)
public StringBuffer reverse() Causes this character sequence to be replaced by the reverse of the sequence. If there are any surrogate pairs included in the sequence, these are treated as single characters for the reverse operation. Thus, the order of the high-low surrogates is never reversed.
Oracle
docs.oracle.com › javase › 6 › docs › api › java › lang › StringBuffer.html
StringBuffer (Java Platform SE 6)
public StringBuffer reverse() Causes this character sequence to be replaced by the reverse of the sequence. If there are any surrogate pairs included in the sequence, these are treated as single characters for the reverse operation. Thus, the order of the high-low surrogates is never reversed.
YouTube
youtube.com › codeash
StringBuffer reverse() Method in Java | How to reverse a sentence using StringBuffer in Java? - YouTube
🔰 StringBuffer reverse() Method :Java StringBuffer reverse() method. The reverse() method of Java StringBuffer class is used to replace this character seque...
Published October 7, 2023 Views 32
Top answer 1 of 2
2
You may use StringUtils reverseDelimited:
Reverses a String that is delimited by a specific character. The Strings between the delimiters are not reversed. Thus java.lang.String becomes String.lang.java (if the delimiter is '.').
So in your case we will use space as a delimiter:
import org.apache.commons.lang.StringUtils;
String reversed = StringUtils.reverseDelimited(sh, ' ');
You may also find a more lengthy solution without it here.
2 of 2
1
Using only JDK methods
String input = "I Need It";
String[] array = input.split(" ");
List<String> list = Arrays.asList(array);
Collections.reverse(list);
String output = String.join(" ", list);
System.out.println(output);
And result is It Need I
Oracle
docs.oracle.com › javase › 10 › docs › api › java › lang › StringBuffer.html
StringBuffer (Java SE 10 & JDK 10 )
public StringBuffer reverse() Causes this character sequence to be replaced by the reverse of the sequence. If there are any surrogate pairs included in the sequence, these are treated as single characters for the reverse operation. Thus, the order of the high-low surrogates is never reversed.