Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

java reverse string

// Not the best way i know but i wanted to challenge myself to do it this way so :)
public static String reverse(String str) {
  char[] oldCharArray = str.toCharArray();
  char[] newCharArray= new char[oldCharArray.length];
  int currentChar = oldCharArray.length-1;
  for (char c : oldCharArray) {
    newCharArray[currentChar] = c;
    currentChar--;
  }
  return new String(newCharArray);
}
Source by www.quora.com #
 
PREVIOUS NEXT
Tagged: #java #reverse #string
ADD COMMENT
Topic
Name
5+1 =