Skip to content

Instantly share code, notes, and snippets.

@linusthe3rd
Last active December 12, 2015 05:59
Show Gist options
  • Save linusthe3rd/4726261 to your computer and use it in GitHub Desktop.
Save linusthe3rd/4726261 to your computer and use it in GitHub Desktop.
reverse a string in java
class Reverse {
public static void main(String[] args) {
reverse("abcde");
}
public static void reverse(String str){
char[] str_arr = str.toCharArray();
int start = 0,
end = str_arr.length-1;
while (start < end){
char temp = str_arr[start];
str_arr[start] = str_arr[end];
str_arr[end] = temp;
start++;
end--;
}
System.out.println(str_arr);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment