Re: Array of object -> Collection of another object??
- From: Roedy Green <my_email_is_posted_on_my_website@xxxxxxxxxxxxxx>
- Date: Sun, 05 Mar 2006 03:18:44 GMT
On 4 Mar 2006 17:21:15 -0800, qazmlp1209@xxxxxxxxxxxxxx wrote, quoted
or indirectly quoted someone who said :
During this conversion, I just noticed that it is not possible to
initialize the Collection to a certain size(equivalent to
array.length). Is that really the case
does this answer your concern?
public ArrayList(Collection<? extends E> c) {
size = c.size();
// Allow 10% room for growth
int capacity = (int) Math.min((size*110L)/100,
Integer.MAX_VALUE);
elementData = (E[]) c.toArray(new Object[capacity]);
The constructor picks the right size automatically.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
.
- References:
- Collection of object -> Array of another object??
- From: qazmlp1209
- Re: Collection of object -> Array of another object??
- From: VisionSet
- Array of object -> Collection of another object??
- From: qazmlp1209
- Collection of object -> Array of another object??
- Prev by Date: refreshing a window
- Next by Date: Re: Array of object -> Collection of another object??
- Previous by thread: Array of object -> Collection of another object??
- Next by thread: Re: Array of object -> Collection of another object??
- Index(es):