There is no real need to use two arrays, and when you do a reference copy you end up working on the same array anyway.
Remember to test your algorithm using an empty array, null, an array with even length and one with odd length.
Here is a single array solution including simple test prints.
public class ReverseTest {
public static String reverse(String s) {
if (s == null)
return null;
char[] ca = s.toCharArray();
for (int i = 0; i < ca.length/2; i++) {
int j = ca.length-i-1;
char c = ca[i];
ca[i] = ca[j];
ca[j] = c;
}
return String.valueOf(ca);
}
public static void main(String[] args) {
System.out.println(reverse(null));
System.out.println(reverse(""));
System.out.println(reverse("54321"));
System.out.println(reverse("4321"));
}
}
Prints:
null
empty line
12345
1234