java reverse string order 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);
}
}
Example 3: String reverse in java
1)
String str = "Hello";
String result = "";
for(int i = str.length()-1; i>=0; i--){
result += str.charAt(i);
}
System.out.println(result);
}