提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
基于LinkedList构造新的同步列表。
/*nowjava - 时代Java*/ //package com.nowjava; 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()); }// 来自 时代Java公众号 - N o w J a v a . 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> synchro