Here you can find the source of swap(ArrayList
Parameter | Description |
---|---|
data | Data |
i | First position |
j | Second position |
T | Object type |
public static <T> void swap(ArrayList<T> data, int i, int j)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; public class Main { /**// ww w.j a va 2 s. c o m * Swap two values in an object array. * * @param data * Data * @param i * First position * @param j * Second position * @param <T> * Object type */ public static <T> void swap(ArrayList<T> data, int i, int j) { T tmp = data.get(i); data.set(i, data.get(j)); data.set(j, tmp); } /** * Swap two values in an object array. * * @param data * Data * @param i * First position * @param j * Second position * @param <T> * Object type */ public static <T> void swap(T[] data, int i, int j) { T tmp = data[i]; data[i] = data[j]; data[j] = tmp; } /** * Swap two values in an integer array. * * @param data * Data * @param i * First position * @param j * Second position */ public static void swap(int[] data, int i, int j) { int tmp = data[i]; data[i] = data[j]; data[j] = tmp; } /** * Swap two values in a byte array. * * @param data * Data * @param i * First position * @param j * Second position */ public static void swap(byte[] data, int i, int j) { byte tmp = data[i]; data[i] = data[j]; data[j] = tmp; } /** * Swap two values in a double array. * * @param data * Data * @param i * First position * @param j * Second position */ public static void swap(double[] data, int i, int j) { double tmp = data[i]; data[i] = data[j]; data[j] = tmp; } /** * Swap two values in a float array. * * @param data * Data * @param i * First position * @param j * Second position */ public static void swap(float[] data, int i, int j) { float tmp = data[i]; data[i] = data[j]; data[j] = tmp; } }