Results 1 to 5 of 5
  1. #1
    Dipke is offline Member
    Join Date
    Aug 2010
    Location
    Leuven, Belgium
    Posts
    86
    Rep Power
    0

    Question ArrayList of ArrayLists

    Hi,

    I need to put data from a file into several ArrayList.
    But the number of ArrayList is not known
    Can i create an ArrayList in witch i put ArrayList<String> ?
    If yes, how do i do that ?

    Kind regards
    Dipke

  2. #2
    mi14chal is offline Member
    Join Date
    Dec 2010
    Posts
    15
    Rep Power
    0

    Default

    Java Code:
    ArrayList<String> s = new ArrayList<String>();
            s.add("test");
            ArrayList<ArrayList> a = new ArrayList<ArrayList>();
            a.add(s);

  3. #3
    Dipke is offline Member
    Join Date
    Aug 2010
    Location
    Leuven, Belgium
    Posts
    86
    Rep Power
    0

    Default

    Thanks,

    Just what i am looking for

  4. #4
    Hibernate's Avatar
    Hibernate is offline Senior Member
    Join Date
    Dec 2010
    Location
    Stockholm, Sweden
    Posts
    222
    Blog Entries
    9
    Rep Power
    4

    Default

    Java Code:
    ArrayList<String> s = new ArrayList<String>();
    s.add("test");
    ArrayList<ArrayList<String>> a = new ArrayList<ArrayList<String>>();
    a.add(s);
    is better, otherwise 'a' is ArrayList<ArrayList<?>>, which I think only have disadvantages over ArrayList<ArrayList<Object>>.

  5. #5
    Dipke is offline Member
    Join Date
    Aug 2010
    Location
    Leuven, Belgium
    Posts
    86
    Rep Power
    0

    Default

    Hello,

    I had already tried
    Java Code:
    ArrayList<ArrayList<String>> a
    bur each time i had an arror.
    Now it is working, so that means that i made a syntax error when trying.

    Many thanks to all and a happy newyear.

    Dipke

Similar Threads

  1. array of ArrayLists
    By imorio in forum New To Java
    Replies: 8
    Last Post: 09-24-2011, 01:05 PM
  2. ArrayLists
    By Freakzoyd in forum New To Java
    Replies: 4
    Last Post: 11-12-2010, 04:27 AM
  3. [SOLVED] A better way to do this - ArrayLists
    By Tshegofatsom in forum New To Java
    Replies: 13
    Last Post: 05-20-2009, 02:05 PM
  4. ArrayList of ArrayLists
    By coolnfunky_raj in forum New To Java
    Replies: 10
    Last Post: 07-03-2008, 10:07 AM

Tags for this Thread

Posting Permissions

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