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

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

Description

swap

License

Open Source License

Declaration

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

Method Source Code


//package com.java2s;
// Licensed under the Apache License, Version 2.0 (the "License");

import java.util.List;

public class Main {
    public static <T> void swap(final List<T> list, int i1, int i2) {
        if (i1 == i2) {
            return;
        }//from   w w  w .ja  v  a  2 s.com
        T temp = list.get(i1);
        list.set(i1, list.get(i2));
        list.set(i2, temp);
    }

    @SuppressWarnings("WeakerAccess")
    public static <T> T get(final List<T> list, final int index, final T defaultValue) {
        return index < list.size() ? list.get(index) : defaultValue;
    }

    @SuppressWarnings("unused")
    public static <T> T get(final List<T> list, final int index) {
        return get(list, index, null);
    }
}

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(List list, int i, int j)
  5. swap(List list, Object object1, Object object2)
  6. swap(List a, int i, int j)
  7. swap(List items, int index1_, int index2_)