1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 package org.chromium.base;
7 import java.util.ArrayList;
8 import java.util.Collections;
9 import java.util.HashSet;
12 * Functions used for easier initialization of Java collections. Inspired by
13 * functionality in com.google.common.collect in Guava but cherry-picked to
14 * bare-minimum functionality to avoid bloat. (http://crbug.com/272790 provides
17 public final class CollectionUtil {
18 private CollectionUtil() {}
20 public static <E> HashSet<E> newHashSet(E... elements) {
21 HashSet<E> set = new HashSet<E>(elements.length);
22 Collections.addAll(set, elements);
26 public static <E> ArrayList<E> newArrayList(E... elements) {
27 ArrayList<E> list = new ArrayList<E>(elements.length);
28 Collections.addAll(list, elements);
32 public static <E> ArrayList<E> newArrayList(Iterable<E> iterable) {
33 ArrayList<E> list = new ArrayList<E>();
34 for (E element : iterable) {