Swap item in list at position first Index with item at position second Index - Android java.util

Android examples for java.util:List Element

Description

Swap item in list at position first Index with item at position second Index

Demo Code


//package com.java2s;

import java.util.List;

public class Main {
    /**// ww w. j a  v  a2s .c o  m
     * Swap item in <code>list</code> at position <code>firstIndex</code> with item at position <code>secondIndex</code>
     *
     * @param list        The list in which to swap the items.
     * @param firstIndex  The position of the first item in the list.
     * @param secondIndex The position of the second item in the list.
     */
    public static void swap(List list, int firstIndex, int secondIndex) {
        Object firstObject = list.get(firstIndex);
        Object secondObject = list.get(secondIndex);
        list.set(firstIndex, secondObject);
        list.set(secondIndex, firstObject);
    }
}

Related Tutorials