reverse a string in java arr code example
Example 1: reverse string java
String string="whatever";
String reverse = new StringBuilder(string).reverse().toString();
System.out.println(reverse);
Example 2: Java reverse string array
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class ReverseStringArrayUsingCollections
{
public static void main(String[] args)
{
List<String> li = new ArrayList<String>();
li.add("java");
li.add("core");
li.add("world");
li.add("hello");
System.out.println("Given list: " + li);
Collections.reverse(li);
System.out.println("After using collections: " + li);
}
}