swap array item by index - Java Collection Framework

Java examples for Collection Framework:Array Index

Description

swap array item by index

Demo Code


//package com.java2s;

public class Main {
    public static <T extends Comparable<T>> void swap(T[] arr, int i, int j) {
        if (i != j) {
            T tmp = arr[i];/*w  ww  .  j  a  v a  2s . c  o m*/
            arr[i] = arr[j];
            arr[j] = tmp;
        }
    }
}

Related Tutorials