swap two array values java 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: java switch two items in an array
String temp = arr[1];
arr[1] = arr[2];
arr[2] = temp;