Here you can find the source of swap(final List
public static <T> void swap(final List<T> list, int i1, int i2)
//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); } }