Java List Swap swapElements(List list, T element1, T element2)

Here you can find the source of swapElements(List list, T element1, T element2)

Description

swap Elements

License

Open Source License

Declaration

public static <T> void swapElements(List<T> list, T element1, T element2) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Collections;

import java.util.List;

public class Main {
    public static <T> void swapElements(List<T> list, T element1, T element2) {
        int index1 = list.indexOf(element1);
        int index2 = list.indexOf(element2);
        if (index1 == -1 || index1 == -1) {
            return;
        }//from w  ww .  j  a va 2s. c  om
        Collections.swap(list, index1, index2);
    }
}

Related

  1. swap(List a, int i, int j)
  2. swap(List items, int index1_, int index2_)
  3. swap(List list, int i1, int i2)
  4. swap(List list, int index1, int index2)
  5. swap(List list, int minIndex, int maxIndex)
  6. swapItems(final List data, int from, int to)
  7. swapListElements(List list, int idx1, int idx2)