United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4822887 : RFE: java.util.Collection should have mthd. that adds an array to the collection

Details
Type:
Enhancement
Submit Date:
2003-02-24
Status:
Resolved
Updated Date:
2003-08-30
Project Name:
JDK
Resolved Date:
2003-08-30
Component:
core-libs
OS:
windows_xp
Sub-Component:
java.util
CPU:
x86
Priority:
P4
Resolution:
Fixed
Affected Versions:
1.4.1
Fixed Versions:
5.0 (tiger)

Related Reports

Sub Tasks

Description

Name: rmT116609			Date: 02/24/2003


DESCRIPTION OF THE PROBLEM :
There should be a method in the java.util.Collections class that will add an array of objects to the collection.  The method's stub would look like the
following:

public boolean addAll(Object[])

The contents of the array would be added to the collection in the order that they are read out of the array starting with an index of 0 and going to .length

I can think of numerous times I've written for loops just to walk over an array and add it to an arraylist.
(Review ID: 181602) 
======================================================================

                                    

Comments
EVALUATION

There is a one-line idiom for this, but it's not fast and (arguably) not as pretty as it could be:

    myCollection.addAll(Arrays.asList(myArray));

It creates a wrapper object, an iterator, and then invokes two methods on the iterator per array element.  The plus side is that the element addition is done from inside the collection implementation so that it can make space for all of the objects at once.

It would be nicer and almost certainly faster to write:

   Collections.addAll(myCollection, myArray);

###@###.### 2003-06-19
                                     
2003-06-19
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
generic
tiger

FIXED IN:
tiger

INTEGRATED IN:
tiger
tiger-b18


                                     
2004-06-14



Hardware and Software, Engineered to Work Together