*
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
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: 1107

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: 19654
    
  18

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: 1107

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Collections.copy
 
Similar Threads
Collections.copy()
Question about Generics in Arrays
Collections copy error
How to add multple lists in one list in insertion order
Collections.copy method for lists ? how it works