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(T[] array, int i, int len)
swap
T tmp = array[i];
array[i] = array[len - i - 1];
array[len - i - 1] = tmp;
T[]swap(T[] array, int indexOne, int indexTwo)
Swaps elements in the array at indexOne and indexTwo.
T elementAtIndexOne = array[indexOne];
array[indexOne] = array[indexTwo];
array[indexTwo] = elementAtIndexOne;
return array;
voidswap(T[] data, int a, int b)
swap
T temp = data[a];
data[a] = data[b];
data[b] = temp;
voidswap(T[] elements, int i, int j)
Swaps the array's elements.
T element = elements[i];
elements[i] = elements[j];
elements[j] = element;
voidswap(T[] ts, int i, int j)
swap
T tmp = ts[i];
ts[i] = ts[j];
ts[j] = tmp;
voidswap2(double v[], int v2[], int i, int j)
swap
double tmp1;
int tmp2;
tmp1 = v[i];
v[i] = v[j];
v[j] = tmp1;
tmp2 = v2[i];
v2[i] = v2[j];
v2[j] = tmp2;
...
voidswap2Bytes(byte[] bytes, int offset)
Swaps the 2 bytes (changes endianness) of the bytes at the given offset.
swapBytesAt(bytes, offset + 0, offset + 1);
voidswap3(String[] a, int x, int y, int z)
Auxiliary method for sorting lexicographically the strings.
String t = a[x];
a[x] = a[y];
a[y] = a[z];
a[z] = t;
voidswapAll(final Object[] array)
swap All
Object tmp;
for (int i = 0, j = array.length - 1; i < j; i++, j--) {
    tmp = array[i];
    array[i] = array[j];
    array[j] = tmp;
voidswapAndPrint(int[] arr, int m, int n)
swap And Print
int temp = arr[m];
arr[m] = arr[n];
arr[n] = temp;
print(arr);