/** * Creates an {@code ArrayList} instance to hold {@code estimatedSize} * elements, <i>plus</i> an unspecified amount of padding; you almost * certainly mean to call {@link #newArrayListWithCapacity} (see that method * for further advice on usage). * * <p><b>Note:</b> This method will soon be deprecated. Even in the rare case * that you do want some amount of padding, it's best if you choose your * desired amount explicitly. * * @param estimatedSize an estimate of the eventual {@link List#size()} of * the new list * @return a new, empty {@code ArrayList}, sized appropriately to hold the * estimated number of elements * @throws IllegalArgumentException if {@code estimatedSize} is negative */ @GwtCompatible(serializable = true) public static <E> ArrayList<E> newArrayListWithExpectedSize( int estimatedSize) { return new ArrayList<E>(computeArrayListCapacity(estimatedSize)); }
/** * Creates an {@code ArrayList} instance to hold {@code estimatedSize} * elements, <i>plus</i> an unspecified amount of padding; you almost * certainly mean to call {@link #newArrayListWithCapacity} (see that method * for further advice on usage). * * <p><b>Note:</b> This method will soon be deprecated. Even in the rare case * that you do want some amount of padding, it's best if you choose your * desired amount explicitly. * * @param estimatedSize an estimate of the eventual {@link List#size()} of * the new list * @return a new, empty {@code ArrayList}, sized appropriately to hold the * estimated number of elements * @throws IllegalArgumentException if {@code estimatedSize} is negative */ @GwtCompatible(serializable = true) public static <E> ArrayList<E> newArrayListWithExpectedSize( int estimatedSize) { return new ArrayList<E>(computeArrayListCapacity(estimatedSize)); }
/** * Creates an {@code ArrayList} instance to hold {@code estimatedSize} * elements, <i>plus</i> an unspecified amount of padding; you almost * certainly mean to call {@link #newArrayListWithCapacity} (see that method * for further advice on usage). * * <p><b>Note:</b> This method will soon be deprecated. Even in the rare case * that you do want some amount of padding, it's best if you choose your * desired amount explicitly. * * @param estimatedSize an estimate of the eventual {@link List#size()} of * the new list * @return a new, empty {@code ArrayList}, sized appropriately to hold the * estimated number of elements * @throws IllegalArgumentException if {@code estimatedSize} is negative */ @GwtCompatible(serializable = true) public static <E> ArrayList<E> newArrayListWithExpectedSize( int estimatedSize) { return new ArrayList<E>(computeArrayListCapacity(estimatedSize)); }
/** * Creates an {@code ArrayList} instance to hold {@code estimatedSize} * elements, <i>plus</i> an unspecified amount of padding; you almost * certainly mean to call {@link #newArrayListWithCapacity} (see that method * for further advice on usage). * * <p><b>Note:</b> This method will soon be deprecated. Even in the rare case * that you do want some amount of padding, it's best if you choose your * desired amount explicitly. * * @param estimatedSize an estimate of the eventual {@link List#size()} of * the new list * @return a new, empty {@code ArrayList}, sized appropriately to hold the * estimated number of elements * @throws IllegalArgumentException if {@code estimatedSize} is negative */ @GwtCompatible(serializable = true) public static <E> ArrayList<E> newArrayListWithExpectedSize( int estimatedSize) { return new ArrayList<E>(computeArrayListCapacity(estimatedSize)); }
/** * Creates a <i>mutable</i> {@code ArrayList} instance containing the given * elements. * * <p><b>Note:</b> essentially the only reason to use this method is when you * will need to add or remove elements later. Otherwise, for non-null elements * use {@link ImmutableList#of()} (for varargs) or {@link * ImmutableList#copyOf(Object[])} (for an array) instead. If any elements * might be null, or you need support for {@link List#set(int, Object)}, use * {@link Arrays#asList}. * * <p>Note that even when you do need the ability to add or remove, this method * provides only a tiny bit of syntactic sugar for {@code newArrayList(}{@link * Arrays#asList asList}{@code (...))}, or for creating an empty list then * calling {@link Collections#addAll}. This method is not actually very useful * and will likely be deprecated in the future. */ @GwtCompatible(serializable = true) public static <E> ArrayList<E> newArrayList(E... elements) { checkNotNull(elements); // for GWT // Avoid integer overflow when a large array is passed in int capacity = computeArrayListCapacity(elements.length); ArrayList<E> list = new ArrayList<E>(capacity); Collections.addAll(list, elements); return list; }
/** * Creates a <i>mutable</i> {@code ArrayList} instance containing the given * elements. * * <p><b>Note:</b> essentially the only reason to use this method is when you * will need to add or remove elements later. Otherwise, for non-null elements * use {@link ImmutableList#of()} (for varargs) or {@link * ImmutableList#copyOf(Object[])} (for an array) instead. If any elements * might be null, or you need support for {@link List#set(int, Object)}, use * {@link Arrays#asList}. * * <p>Note that even when you do need the ability to add or remove, this method * provides only a tiny bit of syntactic sugar for {@code newArrayList(}{@link * Arrays#asList asList}{@code (...))}, or for creating an empty list then * calling {@link Collections#addAll}. This method is not actually very useful * and will likely be deprecated in the future. */ @GwtCompatible(serializable = true) public static <E> ArrayList<E> newArrayList(E... elements) { checkNotNull(elements); // for GWT // Avoid integer overflow when a large array is passed in int capacity = computeArrayListCapacity(elements.length); ArrayList<E> list = new ArrayList<E>(capacity); Collections.addAll(list, elements); return list; }
/** * Creates a <i>mutable</i> {@code ArrayList} instance containing the given * elements. * * <p><b>Note:</b> essentially the only reason to use this method is when you * will need to add or remove elements later. Otherwise, for non-null elements * use {@link ImmutableList#of()} (for varargs) or {@link * ImmutableList#copyOf(Object[])} (for an array) instead. If any elements * might be null, or you need support for {@link List#set(int, Object)}, use * {@link Arrays#asList}. * * <p>Note that even when you do need the ability to add or remove, this method * provides only a tiny bit of syntactic sugar for {@code newArrayList(}{@link * Arrays#asList asList}{@code (...))}, or for creating an empty list then * calling {@link Collections#addAll}. This method is not actually very useful * and will likely be deprecated in the future. */ @GwtCompatible(serializable = true) public static <E> ArrayList<E> newArrayList(E... elements) { checkNotNull(elements); // for GWT // Avoid integer overflow when a large array is passed in int capacity = computeArrayListCapacity(elements.length); ArrayList<E> list = new ArrayList<E>(capacity); Collections.addAll(list, elements); return list; }
/** * Creates a <i>mutable</i> {@code ArrayList} instance containing the given * elements. * * <p><b>Note:</b> essentially the only reason to use this method is when you * will need to add or remove elements later. Otherwise, for non-null elements * use {@link ImmutableList#of()} (for varargs) or {@link * ImmutableList#copyOf(Object[])} (for an array) instead. If any elements * might be null, or you need support for {@link List#set(int, Object)}, use * {@link Arrays#asList}. * * <p>Note that even when you do need the ability to add or remove, this method * provides only a tiny bit of syntactic sugar for {@code newArrayList(}{@link * Arrays#asList asList}{@code (...))}, or for creating an empty list then * calling {@link Collections#addAll}. This method is not actually very useful * and will likely be deprecated in the future. */ @GwtCompatible(serializable = true) public static <E> ArrayList<E> newArrayList(E... elements) { checkNotNull(elements); // for GWT // Avoid integer overflow when a large array is passed in int capacity = computeArrayListCapacity(elements.length); ArrayList<E> list = new ArrayList<E>(capacity); Collections.addAll(list, elements); return list; }