Conditional swap, only swaps the values if array[i] &gt; array[j]
@param array the array to potentially swap values in
@param i the 1st index
@param j the 2nd index
424526
public static void swapC(double[] array, int i, int j)
    {
        
        double tmp_i= array[i];
        double tmp_j = array[j];
        if(tmp_i > tmp_j)
        {
            array[i] = tmp_j;
            array[j] = tmp_i;
        }
    }
1374046
public static void shuffleArray(int[] ar)
    {
        Random rnd = new Random();
        for (int i = ar.length - 1; i > 0; i--)
        {
            int index = rnd.nextInt(i + 1);
            // Simple swap
            int a = ar[index];
            ar[index] = ar[i];
            ar[i] = a;
        }
    }
72379
function swap(array, i, j) {
    var temp = array[i];
    array[i] = array[j];
    array[j] = temp;
  }
1372055
private static function array_shuffle(array &$array)
    {
        for($i = count($array) - 1; $i > 0; $i--)
        {
            $j = mt_rand(0,$i);
            $temp = $array[$i];
            $array[$i] = $array[$j];
            $array[$j] = $temp;
        }
    }
444663
private void swap(int i, int j) {
        int t = pq[i];
        pq[i] = pq[j];
        pq[j] = t;
        qp[pq[i]] = i;
        qp[pq[j]] = j;
    }
1210859
private static final <T> void swap(long[] keys, T[] values, double[] probs, int i, int j) {
    long keySwap = keys[i];
    keys[i] = keys[j];
    keys[j] = keySwap;

    T swapValue = values[i];
    values[i] = values[j];
    values[j] = swapValue;
    
    double swapProb = probs[i];
    probs[i] = probs[j];
    probs[j] = swapProb;
  }
1117301
public void swap(int i, int j) {
    checkBounds(i);
    checkBounds(j);

    if (i == j)
      return;

    copier.copy(tmp, offset(i));
    unsafe.copyMemory(null, offset(j), null, offset(i), elementSpacing);
    unsafe.copyMemory(tmp, firstFieldOffset, null, offset(j), elementSize);
  }
1208010
public static void shuffle(byte[] byteArray) {
		int swapPlace = -1;

		for(int i = 0; i < byteArray.length; i++) {
			swapPlace = (int) (Math.random() * (byteArray.length - 1 ));
			XORSwap.swap(byteArray, i, swapPlace);
		}
	}
1260137
public static void swap(int[] intArray, int index1, int index2) {
        XORSwap.swap(intArray, index1, intArray, index2);
    }
860642
public static void swap(float arr[], int i, int j) {
        float a = arr[i];
        arr[i] = arr[j];
        arr[j] = a;
    }
813598
public static <T> void swap(T[] arr, int a, int b) {
		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;
		}
	}
528670
public static void shuffle(double[] doubleArray) {
		int swapPlace = -1;

		for(int i = 0; i < doubleArray.length; i++) {
            swapPlace = (int) (Math.random() * (doubleArray.length - 1 ));
            TrivialSwap.swap(doubleArray, i, swapPlace);
		}
	}
857610
public static void sort(char[] charArray) {
        boolean swapped = true;
        
        while(swapped) {
            swapped = false;
            
            for(int i = 0; i < (charArray.length - 1 ); i++) {
                if(charArray[i] > charArray[i + 1]) {
                    TrivialSwap.swap(charArray, i, i + 1);
                    
                    swapped = true;
                }
            }            
        }
    }
714194
public static void shuffle(long[] longArray) {
		int swapPlace = -1;

		for(int i = 0; i < longArray.length; i++) {
			swapPlace = (int) (Math.random() * (longArray.length - 1 ));
			XORSwap.swap(longArray, i, swapPlace);
		}
	}
999144
public static void shuffle(char[] charArray) {
		int swapPlace = -1;

		for(int i = 0; i < charArray.length; i++) {
			swapPlace = (int) (Math.random() * (charArray.length - 1 ));
			XORSwap.swap(charArray, i, swapPlace);
		}
	}
690117
private void swap(int[] a, int[] indexes, int i, int j) {
        int swap = indexes[i];
        indexes[i] = indexes[j];
        indexes[j] = swap;
    }
334025
private static void swap(Object[] w, int a, int b) {

        Object t = w[a];

        w[a] = w[b];
        w[b] = t;
    }