Here you can find the source of swap(T[] arr, int index1, int index2)
Parameter | Description |
---|---|
arr | the array to swap in |
index1 | an index of an element to swap |
index2 | an index of an element to swap |
public static <T> T[] swap(T[] arr, int index1, int index2)
//package com.java2s; //License from project: Open Source License public class Main { /**//from ww w . j av a 2 s.co m * Swaps two objects in an array. * @param arr the array to swap in * @param index1 an index of an element to swap * @param index2 an index of an element to swap */ public static <T> T[] swap(T[] arr, int index1, int index2) { arr = arr.clone(); T temp = arr[index1]; arr[index1] = arr[index2]; arr[index2] = temp; return arr; } }