Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: ArrayList value to another ArrayList

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    22
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default ArrayList value to another ArrayList

    Hello, Is there a way to insert one value of an araryList into another ArrayList?
    One arraylist will be printed, the user should chose what value he wants to be inserted into another arraylist (using index numbers).

    ex. Arraylist
    Index 0 | Name: ... Lastname: ... City: ...
    Index 1 | Name: ... Lastname: ... City: ...
    Index 2 | Name: ... Lastname: ... City: ...

    the user choses the value that is in index 1, that name, lastname and city should be inserted into anoter arraylist, thoughts?


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,146
    Thanks
    48
    Thanked 2,158 Times in 2,131 Posts

    Default Re: ArrayList value to another ArrayList

    Is there a way to insert one value of an araryList into another ArrayList?
    Yes. Look at the API doc for the ArrayList class. There are methods for getting a value from an arraylist and methods for adding that value to another arraylist.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    4,802
    My Mood
    Mellow
    Thanks
    176
    Thanked 626 Times in 613 Posts

    Default Re: ArrayList value to another ArrayList

    Are you using parallel ArrayLists to store/track data? If so, stop it.

    Store the data in the instance of a class, appropriately named. Since what you posted looks like an address, I'll call the class Address. If you need to collect a number of Address instances based on user selection, put the whole instance into a collection, maybe an ArrayList<Address>. Then, to print the collected instances, iterate the collection and print each part of the instance as needed or using the Address class' toString() method.

    If I've missed the mark, provide more details about what you're doing.

Similar Threads

  1. How to use an ArrayList and what is its advantage over array?
    By JavaPF in forum Java SE API Tutorials
    Replies: 4
    Last Post: December 21st, 2011, 03:44 AM
  2. private Map<String, ArrayList> xlist = new HashMap<String, ArrayList>();
    By Scotty in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 21st, 2011, 08:37 AM
  3. Ordering ArrayList by 3 conditions as you add to ArrayList
    By aussiemcgr in forum Collections and Generics
    Replies: 4
    Last Post: July 13th, 2010, 02:08 PM
  4. [SOLVED] Extracting an How to ArrayList from an ArrayList and convert to int??
    By igniteflow in forum Collections and Generics
    Replies: 2
    Last Post: August 16th, 2009, 01:11 PM
  5. How to use an ArrayList and what is its advantage over array?
    By JavaPF in forum Java Code Snippets and Tutorials
    Replies: 1
    Last Post: May 17th, 2009, 01:12 PM