I've found this code for swapping case, but I'm a bit confused on how it works.
class Main {
private static String swapCase(String s) {
String r = "";
for (char c : s.toCharArray())
r += c ^= 32; // this line
return r;
}
public static void main(String[] args) {
System.out.println(swapCase("Hello"));
}
}
I understood that it loops over each character. But, I can't wrap my head around the line (especially the XOR operator)
r += c ^= 32;
I mean what's the significance of 32
? How it swaps the case?