code_junkie

Is it good practice to use the XOR (^) operator in Java for boolean checks?

Nov 11th, 2011
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. if (boolean1 ^ boolean2)
  2. {
  3. //do it
  4. }
  5.  
  6. if((boolean1 && !boolean2) || (boolean2 && !boolean1))
  7. {
  8. //do it
  9. }
  10.  
  11. public static boolean xor(boolean a, boolean b) {
  12. return (a && !b) || (b && !a);
  13. }
  14.  
  15. if (term1 ^ term2) { ...
  16.  
  17. if((boolean1 && !boolean2) || (boolean2 && !boolean1))
  18. {
  19. //do it
  20. }
  21.  
  22. if(boolean1 != boolean2)
  23. {
  24. //do it
  25. }
  26.  
  27. str.contains("!=") ^ str.startsWith("not(")
  28.  
  29. str.contains("!=") != str.startsWith("not(")
Add Comment
Please, Sign In to add comment