Java does not provide such a method because it is not possible. Variables are passed to the method by value. Yes, even if these are objects. In this case, we pass the reference to the object by value. Therefore, you cannot change the value of the original variable inside the method that received this variable as a parameter:
int a = 5; int b = 6; swap(a, b); // a is still 5, b is still 6! void swap(int first, int second) { int tmp = first; first = second; second = tmp; }
Alexr source share