Results 1 to 9 of 9
  1. #1
    ankit1801 is offline Member
    Join Date
    Mar 2011
    Posts
    20
    Rep Power
    0

    Question copying contents of an ArrayList to another ArrayList

    i need to copy contents of an arraylist arr1 in another new arraylist arr2. how to copy the contents?

  2. #2
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    12

    Default

    Have you read the ArrayList API? What constructors or methods do you think might be helpful?

  3. #3
    nap_patague is offline Member
    Join Date
    Mar 2011
    Location
    Bulacan, Philippines
    Posts
    23
    Rep Power
    0

    Default

    you can try to loop the contents of array to and then copy the contents to the array 2
    Keep Moving Forward

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,716
    Rep Power
    17

    Default

    (hint: an ArrayList is a Collection)

  5. #5
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,716
    Rep Power
    17

    Default

    Quote Originally Posted by nap_patague View Post
    you can try to loop the contents of array to and then copy the contents to the array 2

    Why is that better than using the constructors and methods provided by ArrayList?

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    26

    Default

    Quote Originally Posted by pbrockway2 View Post
    (hint: an ArrayList is a Collection)
    I remember you telling me that when I was too new to know it </nostalgia>

  7. #7
    nap_patague is offline Member
    Join Date
    Mar 2011
    Location
    Bulacan, Philippines
    Posts
    23
    Rep Power
    0

    Default

    it is just my suggestion. or he can may be use to just initiate it on another arraylist

    newArrayList = oldArrayList
    Keep Moving Forward

  8. #8
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,716
    Rep Power
    17

    Default

    Quote Originally Posted by Darryl.Burke View Post
    I remember you telling me that when I was too new to know it </nostalgia>

    And I remember camickr telling me that text components have a read() method that is better the ugly, slow, memory exhausting line by line code I had!

  9. #9
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,716
    Rep Power
    17

    Default

    Quote Originally Posted by nap_patague View Post
    it is just my suggestion.

    And it's a perfectly workable suggestion. It's just that I can't see why anyone would make it, or follow it given what camickr had previously posted.

    or he can may be use to just initiate it on another arraylist
    newArrayList = oldArrayList

    The OP wanted to copy the contents of the list.

Similar Threads

  1. Replies: 7
    Last Post: 11-22-2010, 01:26 PM
  2. Replies: 19
    Last Post: 08-10-2010, 08:36 AM
  3. Copying ArrayList into an Array
    By Manfizy in forum New To Java
    Replies: 6
    Last Post: 07-16-2009, 07:03 AM
  4. deep copying arraylist to add to a list
    By alvations in forum New To Java
    Replies: 13
    Last Post: 10-08-2008, 03:13 PM
  5. Replies: 2
    Last Post: 04-21-2008, 11:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •