Search code examples
javaswapprimitive-types

Is it possible to write swap method in Java?


Here is the question: write a method that swaps two variables. These two variables should be primitives. It doesn't need to be generic e.g. two int variables. Is there a way?!


Solution

  • Without using an array or objects, no, it is not possible to do it within a method.