Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes Collections.copy method for lists ? how  it works Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Collections.copy method for lists ? how  it works" Watch "Collections.copy method for lists ? how  it works" New topic
Author

Collections.copy method for lists ? how it works

Tanu Gulati
Ranch Hand

Joined: Oct 06, 2008
Posts: 113

I have a code below where i tried to copy an arrayList to listusing Collections.copy method.
I am getting IndexOutofBoundsException since the size of destination list is not equal to the source list.

my question.. is there any Java API help through which i can copy an entire list of any size to a new list(the destination list can be of any size and may be empty).



thanks
Tanu Gulati
rakesh sugirtharaj
Ranch Hand

Joined: Dec 16, 2007
Posts: 151
I think this would work


Cheers!
RSR
Tanu Gulati
Ranch Hand

Joined: Oct 06, 2008
Posts: 113

hey rakesh ..thanks it works ..thanks a lot
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Even simpler:

List list=new ArrayList(arrayList);


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
 
Don't get me started about those stupid light bulbs.
 
subject: Collections.copy method for lists ? how it works
 
Similar Threads
Collections.copy()
Generics - return types
how to print only strings using generics when the list is having multiple types
Collections copy error
Collections.copy