why is reverse method in java not used for string code example
Example 1: reverse string java
String string="whatever";
String reverse = new StringBuilder(string).reverse().toString();
System.out.println(reverse);
Example 2: Reverse a string in java
class ReverseUsingToCharArrayMethod
{
public static void main(String[] args)
{
String str = "Hello World Java";
char[] chTemp = str.toCharArray();
int left, right = 0;
right = chTemp.length - 1;
for(left = 0; left < right ; left++, right--)
{
char temp = chTemp[left];
chTemp[left] = chTemp[right];
chTemp[right]=temp;
}
for(char c : chTemp)
System.out.print(c);
System.out.println();
}
}