Java Utililty Methods Array Swap

List of utility methods to do Array Swap

Description

The list of methods to do Array Swap are organized into topic(s).

Method

voidswap(short[] array, int indexA, int indexB)
swap
short t = array[indexA];
array[indexA] = array[indexB];
array[indexB] = t;
voidswap(String a[], int i, int j)
Private method to swap two elements in the array
String T;
T = a[i];
a[i] = a[j];
a[j] = T;
voidswap(T[] a, int i1, int i2)
Swaps objects at specified index in array
T temp = a[i1];
a[i1] = a[i2];
a[i2] = temp;
voidswap(T[] a, int idx1, int idx2)
Swaps two elements in an array.
T tmp = a[idx1];
a[idx1] = a[idx2];
a[idx2] = tmp;
voidswap(T[] arr, int a, int b)
Swaps the elements at position a and b in the array arr.
if (a < 0 || a > arr.length || b < 0 || b > arr.length)
    throw new IllegalArgumentException("swap position out of bounds.");
if (a != b) {
    T t = arr[a];
    arr[a] = arr[b];
    arr[b] = t;
voidswap(T[] arr, int i, int j)
Swap values in array
T t = arr[i];
arr[i] = arr[j];
arr[j] = t;
T[]swap(T[] arr, int index1, int index2)
Swaps two objects in an array.
arr = arr.clone();
T temp = arr[index1];
arr[index1] = arr[index2];
arr[index2] = temp;
return arr;
voidswap(T[] arr, int pos1, int pos2)
Exchanges two elements in the array.
final T temp = arr[pos1];
arr[pos1] = arr[pos2];
arr[pos2] = temp;
voidswap(T[] array, int a, int b)
Swaps the elements at the given positions in the array.
T temp = array[a];
array[a] = array[b];
array[b] = temp;
voidswap(T[] array, int first_idx, int last_idx)
swap
T tmp = array[first_idx];
array[first_idx] = array[last_idx];
array[last_idx] = tmp;