how to swap in java using function in array code example
Example 1: java array swap
public static void swap(int x, int y, int[] arr) {
int temp = arr[x];
arr[x] = arr[y];
arr[y] = temp;
}
Example 2: array.swap java
String temp = arr[1];
arr[1] = arr[2];
arr[2] = temp;