Win a copy of Mesos in Action this week in the Cloud/Virtualizaton 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);
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic