Check out example codes for "java array swap". It will help you in understanding the concepts better.

Code Example 1

public static void swap(int x, int y, int[] arr) {
  	int temp = arr[x];
  	arr[x] = arr[y];
  	arr[y] = temp;
}

Learn ReactJs, React Native from akashmittal.com