Java examples for java.util:List Creation
Constructs a new synchronized List based on a LinkedList .
//package com.java2s; import java.util.ArrayList; import java.util.Collections; import java.util.LinkedList; import java.util.List; public class Main { public static void main(String[] argv) { System.out.println(synchronizedList()); }//from www .ja v a2s. c o m /** * Constructs a new synchronized {@code List} based on a {@link LinkedList}. * * @return a synchronized List */ public static <E> List<E> synchronizedList() { return Collections.synchronizedList(new LinkedList<E>()); } /** * Constructs a new synchronized {@code List} based on a {@link ArrayList} * with the specified {@code initialCapacity}. * * @param initialCapacity * the initial capacity of the array list * * @return a synchronized List */ public static <E> List<E> synchronizedList(final int initialCapacity) { return Collections.synchronizedList(new ArrayList<E>( initialCapacity)); } }