Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Collections.copy method for lists ? how it works

 
Tanu Gulati
Ranch Hand
Posts: 113
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).

 
rakesh sugirtharaj
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this would work
 
Tanu Gulati
Ranch Hand
Posts: 113
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey rakesh ..thanks it works ..thanks a lot
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even simpler:

List list=new ArrayList(arrayList);
 
I yam what I yam and that's all that I yam - the great philosopher Popeye. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!