aspose file tools*
The moose likes Java in General and the fly likes Collections.copy Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Collections.copy" Watch "Collections.copy" New topic
Author

Collections.copy

Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1106

why doesn't this work



it complains the destination isn't big enough to hold the src.
but both Lists are exactly the same size?

My only thoughts are that java is fibbing and doesn't actually allocate memory for the new list at creation just goes "oh yes must remember that".

Oh yes this is in a jsp page if that makes a difference.

I have got it working by going, just want to know why i need to.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19541
    
  16

Wendy Gibbons wrote:why doesn't this work



it complains the destination isn't big enough to hold the src.
but both Lists are exactly the same size?

My only thoughts are that java is fibbing and doesn't actually allocate memory for the new list at creation just goes "oh yes must remember that".

The new List has a capacity to store the elements (memory allocation), but it's still empty. That means it has a size of 0. Size and capacity are two very different things. The only thing that you can say about them is that the capacity is never smaller than the size.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1106

oh yes, thank you.
Just reading the source now to answer my other questions about why this matters as collections grow as you add items to them.
 
Consider Paul's rocket mass heater.
 
subject: Collections.copy
 
Similar Threads
How to add multple lists in one list in insertion order
Collections.copy method for lists ? how it works
Collections copy error
Question about Generics in Arrays
Collections.copy()