Reverse a string in java
// reverse a string using ByteArray
class ReverseStringByteArray
{
public static void main(String[] args)
{
String input = "HelloWorld";
// getBytes() method to convert string into bytes[].
byte[] strByteArray = input.getBytes();
byte[] output = new byte[strByteArray.length];
// store output in reverse order
for(int a = 0; a < strByteArray.length; a++)
output[a] = strByteArray[strByteArray.length - a - 1];
System.out.println(new String(output));
}
}