reversing a string in java in a method code example
Example 1: how to reverse a string in java
public class ReverseString {
public static void main(String[] args) {
String s1 = "neelendra";
for(int i=s1.length()-1;i>=0;i--)
{
System.out.print(s1.charAt(i));
}
}
}
Example 2: Reverse a string in java
class ReverseStringByteArray
{
public static void main(String[] args)
{
String input = "HelloWorld";
byte[] strByteArray = input.getBytes();
byte[] output = new byte[strByteArray.length];
for(int a = 0; a < strByteArray.length; a++)
output[a] = strByteArray[strByteArray.length - a - 1];
System.out.println(new String(output));
}
}