java swap two elements 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;