Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Main {
    public static void main(String[] args) {
        // create vector object 
        List<String> vector = new ArrayList<String>();

        // populate the vector
        vector.add("1");
        vector.add("2");
        vector.add("3");
        vector.add("4");
        vector.add("from java2s.com");

        System.out.println("Before swap: " + vector);

        // swap the elements
        Collections.swap(vector, 0, 4);

        System.out.println("After swap: " + vector);
    }
}