Re: Array of object -> Collection of another object??



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.
.