This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
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
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply 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
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Collections.copy method for lists ? how it works
 
Similar Threads
Generics - return types
Collections copy error
Collections.copy()
Collections.copy
how to print only strings using generics when the list is having multiple types