Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.List;

public class Main {

    public static <T> void exchange(List<T> list, int indexA, int indexB) {
        indexA -= 1;
        indexB -= 1;

        if (indexA >= list.size() || indexB >= list.size() || indexA < 0 || indexB < 0 || indexA == indexB) {
            return;
        } else {
            T _a = list.get(indexA);
            T _b = list.get(indexB);
            list.remove(indexA);
            list.add(indexA, _b);
            list.remove(indexB);
            list.add(indexB, _a);
            return;
        }
    }
}