Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

reverse a string in java

// 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: #reverse #string #java
ADD COMMENT
Topic
Name
1+5 =