Java List Swap swap(List list, int i1, int i2)

Here you can find the source of swap(List list, int i1, int i2)

Description

Swaps two entries in a list.

License

Open Source License

Declaration

public static <T> void swap(List<T> list, int i1, int i2) 

Method Source Code

//package com.java2s;
/*/*from   w ww  .j  av  a 2 s.  c  om*/
 * BioAssay Ontology Annotator Tools
 * 
 * (c) 2014-2016 Collaborative Drug Discovery Inc.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License 2.0
 * as published by the Free Software Foundation:
 * 
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 */

import java.util.*;

public class Main {
    /**
     * Swaps two entries in a list.
     */
    public static <T> void swap(List<T> list, int i1, int i2) {
        T v1 = list.get(i1), v2 = list.get(i2);
        list.set(i1, v2);
        list.set(i2, v1);
    }
}

Related

  1. swap(final List list, int i1, int i2)
  2. swap(List list, int i, int j)
  3. swap(List list, Object object1, Object object2)
  4. swap(List a, int i, int j)
  5. swap(List items, int index1_, int index2_)
  6. swap(List list, int index1, int index2)
  7. swap(List list, int minIndex, int maxIndex)
  8. swapElements(List list, T element1, T element2)
  9. swapItems(final List data, int from, int to)