Java List interface

https:/‮ww/‬w.lautturi.com
Java List interface
/**
 * @author lautturi.com 
 * Java example: java list example
 */

import java.util.*;

public class Lautturi {
	public static void main(String[] args) {

		List<Integer> list = new ArrayList<Integer>();

		// add new element at designated location
		list.add(0, 4);
		list.add(1, 5);

		System.out.println(list);

		// create another list in java
		List<Integer> anotherList = new ArrayList<Integer>();

		anotherList.add(1);
		anotherList.add(2);
		anotherList.add(3);

		// add another list to list in java
		list.addAll(1, anotherList);

		System.out.println(list);

		// remove/delete element from list in java 
		list.remove(1);
		System.out.println(list);

		// get the element from list at index 3
		Integer num = list.get(3);
		System.out.println(num);

		// change element at index 0 in list 
		list.set(0, 5);

		System.out.println(list);

	}
}

output:

[4, 5]
[4, 1, 2, 3, 5]
[4, 2, 3, 5]
5
[5, 2, 3, 5]
Created Time:2017-10-03 16:41:47  Author:lautturi