< prev index next >
src/java.base/share/classes/java/util/Collections.java
Print this page
8193031: Collections.addAll is likely to perform worse than Collection.addAll
Reviewed-by: smarks, forax
*** 5396,5407 ****
/**
* Adds all of the specified elements to the specified collection.
* Elements to be added may be specified individually or as an array.
* The behavior of this convenience method is identical to that of
! * {@code c.addAll(Arrays.asList(elements))}, but this method is likely
! * to run significantly faster under most implementations.
*
* <p>When elements are specified individually, this method provides a
* convenient way to add a few elements to an existing collection:
* <pre>
* Collections.addAll(flavors, "Peaches 'n Plutonium", "Rocky Racoon");
--- 5396,5406 ----
/**
* Adds all of the specified elements to the specified collection.
* Elements to be added may be specified individually or as an array.
* The behavior of this convenience method is identical to that of
! * {@code c.addAll(Arrays.asList(elements))}.
*
* <p>When elements are specified individually, this method provides a
* convenient way to add a few elements to an existing collection:
* <pre>
* Collections.addAll(flavors, "Peaches 'n Plutonium", "Rocky Racoon");
*** 5420,5434 ****
* {@code elements} prevents it from being added to {@code c}
* @see Collection#addAll(Collection)
* @since 1.5
*/
@SafeVarargs
public static <T> boolean addAll(Collection<? super T> c, T... elements) {
! boolean result = false;
! for (T element : elements)
! result |= c.add(element);
! return result;
}
/**
* Returns a set backed by the specified map. The resulting set displays
* the same ordering, concurrency, and performance characteristics as the
--- 5419,5431 ----
* {@code elements} prevents it from being added to {@code c}
* @see Collection#addAll(Collection)
* @since 1.5
*/
@SafeVarargs
+ @SuppressWarnings("varargs")
public static <T> boolean addAll(Collection<? super T> c, T... elements) {
! return c.addAll(Arrays.asList(elements));
}
/**
* Returns a set backed by the specified map. The resulting set displays
* the same ordering, concurrency, and performance characteristics as the
< prev index next >