Java List Swap swap(List list, Object object1, Object object2)

Here you can find the source of swap(List list, Object object1, Object object2)

Description

Swap object1 with object2 in the list.

License

Open Source License

Parameter

Parameter Description
list a parameter
object1 a parameter
object2 a parameter

Declaration

@SuppressWarnings("unchecked")
public static void swap(List list, Object object1, Object object2) 

Method Source Code

//package com.java2s;
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt

import java.util.List;

public class Main {
    /**//from w  ww  .  j  a  va2 s. co  m
     * Swap object1 with object2 in the list.
     * 
     * @param list
     * @param object1
     * @param object2
     */
    @SuppressWarnings("unchecked")
    public static void swap(List list, Object object1, Object object2) {
        int indexObject1 = list.indexOf(object1);
        int indexObject2 = list.indexOf(object2);
        list.set(indexObject2, object1);
        list.set(indexObject1, object2);
    }
}

Related

  1. swap(final L list1, final L list2, final int index)
  2. swap(final List list, final int index0, final int index1)
  3. swap(final List list, final int index1, final int index2)
  4. swap(final List list, int i1, int i2)
  5. swap(List list, int i, int j)
  6. swap(List a, int i, int j)
  7. swap(List items, int index1_, int index2_)
  8. swap(List list, int i1, int i2)
  9. swap(List list, int index1, int index2)