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 5 of 5

Thread: Convert ArrayList to multi-dimensional array

  1. #1
    Member
    Join Date
    Feb 2013
    Posts
    57
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Question Convert ArrayList to multi-dimensional array

    I am having troubles to convert an ArrayList of Object data to a multi-d array. The code below is the pseudo code:

    Person p1 = new Person("Tim", 21);
    Person p2 = new Person("Sara", 23);
    Person p3 = new Person("Henry", 27);
     
    ArrayList<Person> people = new ArrayList();
    people.add(p1);
    people.add(p2);
    people.add(p3);
     
    Object[][] peopleArray;
     
    for(Person p: people)
    {
        //code to convert people ArrayList to peopleArray
    }

    Could anyone tell me how I could populate this array with the people's ArrayList?
    I need this array because I'm trying to create a JTable using it's constructor JTable([][])

    Thanks much appreciated


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Convert ArrayList to multi-dimensional array

    Is this what you want:
    The data from the next object in the arraylist will go to the contents of a row in the array.
    On the row the data from the object goes into the columns of the row.
    You need to define what data goes in the columns of the row.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Feb 2013
    Posts
    57
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Convert ArrayList to multi-dimensional array

    Yes. The Person objects itself will be stored in the rows of the array, and the contents of the Person objects (such as Name, Age etc) will be stored each of the columns in the array.

    Thanks

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Convert ArrayList to multi-dimensional array

    Do you have the solution now?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Member
    Join Date
    Feb 2013
    Posts
    57
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Convert ArrayList to multi-dimensional array

    Yes I do. Thanks for your help

Similar Threads

  1. convert arraylist to 2D array
    By ishrne in forum Object Oriented Programming
    Replies: 5
    Last Post: April 5th, 2013, 07:57 AM
  2. Searching and displaying results in a multi-dimensional array.
    By wfalcon2012 in forum Collections and Generics
    Replies: 2
    Last Post: February 18th, 2012, 08:06 PM
  3. How can I create a jigsaw puzzle with Array multi-dimensional?
    By ivan8 in forum What's Wrong With My Code?
    Replies: 15
    Last Post: December 4th, 2011, 08:13 PM
  4. Replies: 3
    Last Post: October 26th, 2011, 03:37 PM
  5. Multi Dimensional Array help NEEDED URGENT
    By bonjovi4u in forum Loops & Control Statements
    Replies: 5
    Last Post: February 13th, 2010, 12:44 AM

Tags for this Thread