Results 1 to 5 of 5
  1. #1
    gapper is offline Member
    Join Date
    Jan 2008
    Posts
    17
    Rep Power
    0

    Default 2 dimensional Lists

    As we know, simple arrays can be of multi dimensions. Can an ArrayList/Vector be of 2 dimensional? Please dive code samples.

    Thanks in advance

  2. #2
    roots's Avatar
    roots is offline Moderator
    Join Date
    Jan 2008
    Location
    Dallas
    Posts
    293
    Rep Power
    9

    Default

    How about Vector of Vector

    Java Code:
    Vector<Vector<String>> twoDimensionalVector ;
    dont worry newbie, we got you covered.

  3. #3
    CaptainMorgan's Avatar
    CaptainMorgan is offline Moderator
    Join Date
    Dec 2007
    Location
    NewEngland, US
    Posts
    835
    Rep Power
    10

    Default

    This can probably lead to confusing code down the road, and I would hope someone might have something better but you can try this:
    Java Code:
             ArrayList< ArrayList<String> > my_2dlist = 
                    new ArrayList< ArrayList<String> >();
             
             my_2dlist.add( new ArrayList<String>() );
             my_2dlist.get(0).add("Hello, World");
             System.out.println(my_2dlist.get(0).get(0));
    Vote for the new slogan to our beloved Java Forums! (closes on September 4, 2008)
    Want to voice your opinion on your IDE/Editor of choice? Vote now!
    Got a little Capt'n in you? (drink responsibly)

  4. #4
    roots's Avatar
    roots is offline Moderator
    Join Date
    Jan 2008
    Location
    Dallas
    Posts
    293
    Rep Power
    9

    Default

    lol captain .. what a timing ..
    dont worry newbie, we got you covered.

  5. #5
    CaptainMorgan's Avatar
    CaptainMorgan is offline Moderator
    Join Date
    Dec 2007
    Location
    NewEngland, US
    Posts
    835
    Rep Power
    10

    Default

    Heh, jinx!
    Vote for the new slogan to our beloved Java Forums! (closes on September 4, 2008)
    Want to voice your opinion on your IDE/Editor of choice? Vote now!
    Got a little Capt'n in you? (drink responsibly)

Similar Threads

  1. How to initialize a two dimensional Array
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-14-2008, 08:48 PM
  2. Replies: 2
    Last Post: 01-07-2008, 08:45 PM
  3. Adding numbers in a 2 dimensional array
    By j0shizabeast in forum New To Java
    Replies: 2
    Last Post: 11-27-2007, 05:31 AM
  4. Help with array multi-dimensional
    By barney in forum New To Java
    Replies: 1
    Last Post: 07-31-2007, 08:00 PM
  5. Tudu Lists 2.0
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 07-11-2007, 03:32 PM

Posting Permissions

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