Results 1 to 2 of 2
  1. #1
    Join Date
    May 2010
    Posts
    24
    Rep Power
    0

    Default Copy a specified element from one array list to another arraylist

    I have two arraylists: A & B. How do I copy a single element of A into B? The elements in question are objects of a custom defined class.

  2. #2
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    6

    Default

    Quote Originally Posted by TaxpayersMoney View Post
    I have two arraylists: A & B. How do I copy a single element of A into B? The elements in question are objects of a custom defined class.
    you can loop through the arraylist to find the object and when found use B.add(yourObject);

    Small example

    Java Code:
    MyClass p = a2.get(0);
    a1.add(p);

    Suppose your element is the first Element in the arraylist a2, get it and add it to your arraylist a1.

Similar Threads

  1. Replies: 9
    Last Post: 02-10-2010, 03:19 AM
  2. Replies: 1
    Last Post: 03-31-2009, 06:40 AM
  3. Replies: 0
    Last Post: 03-03-2009, 08:46 AM
  4. [SOLVED] ArrayList element to int
    By grahamb314 in forum New To Java
    Replies: 9
    Last Post: 11-22-2008, 05:09 PM
  5. adding list to an array element
    By Preethi in forum New To Java
    Replies: 5
    Last Post: 09-25-2008, 04:23 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
  •