Java Program to reverse a string using StringBuffer class.
Here, in StringBuffer class we will use reverse() method to reverse a string.
💡reverse() method is in-built in StringBuffer class.
Following is JAVA code to reverse a string using StringBuffer class:
import java.util.Scanner;
public class Test{
public static void main(String[]args)
{
StringBuffer sb = new StringBuffer("hello world");
System.out.print(sb.reverse());
}
}
Output:
dlrow olleh
To check, reverse a String using String class,
click here.