1public static void swap(int x, int y, int[] arr) {
2 int temp = arr[x];
3 arr[x] = arr[y];
4 arr[y] = temp;
5}
1public static final <T> void swap (T[] a, int i, int j) {
2 T t = a[i];
3 a[i] = a[j];
4 a[j] = t;
5}
6
7public static final <T> void swap (List<T> l, int i, int j) {
8 Collections.<T>swap(l, i, j);
9}
10
11private void test() {
12 String [] a = {"Hello", "Goodbye"};
13 swap(a, 0, 1);
14 System.out.println("a:"+Arrays.toString(a));
15 List<String> l = new ArrayList<String>(Arrays.asList(a));
16 swap(l, 0, 1);
17 System.out.println("l:"+l);
18}
19