Here is the original code:
public static String reverseString(String s){ if(s == null) return ""; char[] rev = s.toCharArray(); int i = 0, j = s.length() - 1; while(i < j) { rev[i] ^= rev[j]; rev[j] ^= rev[i]; rev[i++] ^= rev[j--]; } return String.valueOf(rev); }
My question is how does Xor work in swapping character values here, and why is rev[i++]^=rev[j--] needed here?