src/share/classes/java/util/Collections.java

Print this page




3810      *
3811      * <p>When elements are specified individually, this method provides a
3812      * convenient way to add a few elements to an existing collection:
3813      * <pre>
3814      *     Collections.addAll(flavors, "Peaches 'n Plutonium", "Rocky Racoon");
3815      * </pre>
3816      *
3817      * @param c the collection into which <tt>elements</tt> are to be inserted
3818      * @param elements the elements to insert into <tt>c</tt>
3819      * @return <tt>true</tt> if the collection changed as a result of the call
3820      * @throws UnsupportedOperationException if <tt>c</tt> does not support
3821      *         the <tt>add</tt> operation
3822      * @throws NullPointerException if <tt>elements</tt> contains one or more
3823      *         null values and <tt>c</tt> does not permit null elements, or
3824      *         if <tt>c</tt> or <tt>elements</tt> are <tt>null</tt>
3825      * @throws IllegalArgumentException if some property of a value in
3826      *         <tt>elements</tt> prevents it from being added to <tt>c</tt>
3827      * @see Collection#addAll(Collection)
3828      * @since 1.5
3829      */

3830     public static <T> boolean addAll(Collection<? super T> c, T... elements) {
3831         boolean result = false;
3832         for (T element : elements)
3833             result |= c.add(element);
3834         return result;
3835     }
3836 
3837     /**
3838      * Returns a set backed by the specified map.  The resulting set displays
3839      * the same ordering, concurrency, and performance characteristics as the
3840      * backing map.  In essence, this factory method provides a {@link Set}
3841      * implementation corresponding to any {@link Map} implementation.  There
3842      * is no need to use this method on a {@link Map} implementation that
3843      * already has a corresponding {@link Set} implementation (such as {@link
3844      * HashMap} or {@link TreeMap}).
3845      *
3846      * <p>Each method invocation on the set returned by this method results in
3847      * exactly one method invocation on the backing map or its <tt>keySet</tt>
3848      * view, with one exception.  The <tt>addAll</tt> method is implemented
3849      * as a sequence of <tt>put</tt> invocations on the backing map.




3810      *
3811      * <p>When elements are specified individually, this method provides a
3812      * convenient way to add a few elements to an existing collection:
3813      * <pre>
3814      *     Collections.addAll(flavors, "Peaches 'n Plutonium", "Rocky Racoon");
3815      * </pre>
3816      *
3817      * @param c the collection into which <tt>elements</tt> are to be inserted
3818      * @param elements the elements to insert into <tt>c</tt>
3819      * @return <tt>true</tt> if the collection changed as a result of the call
3820      * @throws UnsupportedOperationException if <tt>c</tt> does not support
3821      *         the <tt>add</tt> operation
3822      * @throws NullPointerException if <tt>elements</tt> contains one or more
3823      *         null values and <tt>c</tt> does not permit null elements, or
3824      *         if <tt>c</tt> or <tt>elements</tt> are <tt>null</tt>
3825      * @throws IllegalArgumentException if some property of a value in
3826      *         <tt>elements</tt> prevents it from being added to <tt>c</tt>
3827      * @see Collection#addAll(Collection)
3828      * @since 1.5
3829      */
3830     @SafeVarargs
3831     public static <T> boolean addAll(Collection<? super T> c, T... elements) {
3832         boolean result = false;
3833         for (T element : elements)
3834             result |= c.add(element);
3835         return result;
3836     }
3837 
3838     /**
3839      * Returns a set backed by the specified map.  The resulting set displays
3840      * the same ordering, concurrency, and performance characteristics as the
3841      * backing map.  In essence, this factory method provides a {@link Set}
3842      * implementation corresponding to any {@link Map} implementation.  There
3843      * is no need to use this method on a {@link Map} implementation that
3844      * already has a corresponding {@link Set} implementation (such as {@link
3845      * HashMap} or {@link TreeMap}).
3846      *
3847      * <p>Each method invocation on the set returned by this method results in
3848      * exactly one method invocation on the backing map or its <tt>keySet</tt>
3849      * view, with one exception.  The <tt>addAll</tt> method is implemented
3850      * as a sequence of <tt>put</tt> invocations on the backing map.