JDK-4822887 : RFE: java.util.Collection should have mthd. that adds an array to the collection
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.util:collections
  • Affected Version: 1.4.1
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2003-02-24
  • Updated: 2021-03-03
  • Resolved: 2003-08-30
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
5.0 tigerFixed
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
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: generic tiger FIXED IN: tiger INTEGRATED IN: tiger tiger-b18
14-06-2004

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
19-06-2003