Given two integers, swap them in a single line in Java.

There are several expressions to swap two variables in a single line in Java:

1. Using Bitwise XOR (^) Operator

Download  Run Code

2. Using Addition and Subtraction Operator

Download  Run Code

3. Using Multiplication and Division Operator

Download  Run Code

 
It is worth noting that we can also use all the above-discussed methods with C/C++.