Java Array Swap swap(T[] data, int a, int b)

Here you can find the source of swap(T[] data, int a, int b)

Description

swap

License

Creative Commons License

Declaration

public static <T extends Comparable<? super T>> void swap(T[] data, int a, int b) 

Method Source Code

//package com.java2s;
//<div>Icons made by <a href="http://www.flaticon.com/authors/freepik" title="Freepik">Freepik</a> from <a href="http://www.flaticon.com" title="Flaticon">www.flaticon.com</a> is licensed by <a href="http://creativecommons.org/licenses/by/3.0/" title="Creative Commons BY 3.0" target="_blank">CC 3.0 BY</a></div>

public class Main {
    public static <T extends Comparable<? super T>> void swap(T[] data, int a, int b) {
        T temp = data[a];//from   w  w w .ja  va  2s . c  o  m
        data[a] = data[b];
        data[b] = temp;
    }
}

Related

  1. swap(T[] arr, int pos1, int pos2)
  2. swap(T[] array, int a, int b)
  3. swap(T[] array, int first_idx, int last_idx)
  4. swap(T[] array, int i, int len)
  5. swap(T[] array, int indexOne, int indexTwo)
  6. swap(T[] elements, int i, int j)
  7. swap(T[] ts, int i, int j)
  8. swap2(double v[], int v2[], int i, int j)
  9. swap2Bytes(byte[] bytes, int offset)