swap element in a List - Android java.util

Android examples for java.util:List Element

Description

swap element in a List

Demo Code


//package com.java2s;
import java.util.List;

public class Main {
    public static void swap(List<?> list, int i, int j) {
        final List l = list;
        l.set(i, l.set(j, l.get(i)));//from   www.  java  2 s  .c om
    }

    private static void swap(Object[] arr, int i, int j) {
        Object tmp = arr[i];
        arr[i] = arr[j];
        arr[j] = tmp;
    }
}

Related Tutorials