There are many possible ways to reverse String in Java. We can use a StringBuffer, StringBuilder, and iteration, etc.

1). Using a reverse() method of StringBuilder class

import java.lang.*;
import java.io.*;
import java.util.*;

class Main
{
public static void main(String[] args)
{
String input = “TutorialWorld”;

StringBuilder str = new StringBuilder();

str.append(input);

str = str.reverse();

System.out.println(str);
}
}

2). By Converting String to character array using toCharArray() and then reverse.

Here we will first convert String in to a character array. For this conversion, we have the toCharArray() method. After that iterate this array and print it from last to first order.

import java.lang.*;
import java.io.*;
import java.util.*;

class Main
{
public static void main(String[] args)
{
String input = “TutorialWorld”;

char[] try1 = input.toCharArray();

for (int i = try1.length-1; i>=0; i–)
System.out.print(try1[i]);
}
}

3). Using ArrayList object

Using ArrayList which is in Collection Framework in Java. We will first convert the string into the array of character by using toCharArray(). And after the conversion, we will add the characters of the array into the ArrayList object. In Collections, there is a reverse() method that can reverse the array list in one go.

import java.lang.*;
import java.io.*;
import java.util.*;

class ReverseString
{
public static void main(String[] args)
{
String str = “TutorialWorld”;
char[] chr = str.toCharArray();
List list1 = new ArrayList<>();

for (char c: chr)
list1.add(c);

Collections.reverse(list1);
ListIterator li = list1.listIterator();
while (li.hasNext())
System.out.print(li.next());
}
}