Program to Reverse a string in Java

public static String reverseString(String reverseString) {
 StringBuffer reversedString = new StringBuffer();
 char[] reverseArray = reverseString.toCharArray();
 for(int i = reverseArray.length-1; i>=0; i--) {
  reversedString.append(reverseArray[i]);
 }
 return reversedString.toString();
}

public static void main(String[] args) {
 String reversedString = reverseString("Keshav");
 System.out.println("Reversed String "+reversedString);
}

Comments

Popular posts from this blog

Android - Using KeyStore to encrypt and decrypt the data

Stack and Queue

Java Reflection API