List of utility methods to do Array Swap
void | swapPerTowElement(int[] arr) swap Per Tow Element int len = arr.length; for (int i = 1; i < len; i += 2) { swap(arr, i, i - 1); |
void | swapReferences(Object[] a, int index1, int index2) Method to swap to elements in an array. Object tmp = a[index1]; a[index1] = a[index2]; a[index2] = tmp; |
void | swapRgbColorComponents(byte[] pixelArray) Swaps every R channel with B channel for every pixel in passed array thus converting beetwen RGB and BGR. if (pixelArray == null) throw new IllegalArgumentException("pixelArray cannot be null."); for (int i = 0; i < pixelArray.length; i += 3) { byte temp = pixelArray[i]; pixelArray[i] = pixelArray[i + 2]; pixelArray[i + 2] = temp; |
String[] | swapTokens(String grid[]) swap Tokens String stringBoard[] = new String[grid.length]; for (int i = 0; i < grid.length; i++) { stringBoard[i] = grid[i].replace('Y', 'R').replace('R', 'Y'); return stringBoard; |
void | swapValues(double[] arr, double v1, double v2) This changes all occurrences of the value v1 to v2 and vice versa. for (int i = 0; i < arr.length; ++i) { if (arr[i] == v1) { arr[i] = v2; } else if (arr[i] == v2) { arr[i] = v1; |
void | swapZeros(int[] input, int zeroCount) swap Zeros int inputLength = input.length; int nonZeroLength = inputLength - zeroCount; for (int i = 0; i < nonZeroLength; i++) { if (inputLength <= nonZeroLength) { break; int element = input[i]; if (element == 0) { ... |