Results 1 to 6 of 6
  1. #1
    mike_ledis is offline Member
    Join Date
    Mar 2010
    Posts
    24
    Rep Power
    0

    Default Arraylist of arraylists

    Hello and congratulations for your job! Suppose that i declare an arraylist like the following

    Arraylist stringArraylist<string>;

    Is there any way to have an arraylist that holds arraylists like the uper?

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,891
    Rep Power
    25

    Default Re: Arraylist of arraylists

    Does the code compile?

    like the uper?
    What is "uper"?
    Last edited by Norm; 03-31-2012 at 10:59 PM.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    mike_ledis is offline Member
    Join Date
    Mar 2010
    Posts
    24
    Rep Power
    0

    Default Re: Arraylist of arraylists

    I need to declare an arraylist that holds arraylists of the following kind.
    Arraylist stringArraylist<string>;

    I didnt try because i dont know how to declare it.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,891
    Rep Power
    25

    Default Re: Arraylist of arraylists

    Have you ever written an ArrayList that holds a String? You define the data type first followed by the name to be given to the object .
    The symbol: String can be replaced with any other class name.

    Check out the tutorial:
    http://docs.oracle.com/javase/tutori...ybigindex.html

    Find Generics and read on. There are two places to read in.
    Last edited by Norm; 03-31-2012 at 11:17 PM.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    jwolf is offline Member
    Join Date
    Jan 2012
    Location
    Minnesota
    Posts
    4
    Rep Power
    0

    Default Re: Arraylist of arraylists

    Yes it is possible. An instance of the ArrayList class is declared, ArrayList<datatype> myList.
    So you just need to make the an ArrayList of the type you want, i.e. if you wanted strings...

    ArrayList<ArrayList<String>> list = new ArrayList<ArrayList<String>>();

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. Arraylists
    By talia in forum New To Java
    Replies: 5
    Last Post: 01-30-2012, 07:44 PM
  2. Replies: 12
    Last Post: 07-07-2011, 09:49 PM
  3. ArrayList of ArrayLists
    By Dipke in forum New To Java
    Replies: 4
    Last Post: 12-29-2010, 09:56 AM
  4. ArrayLists
    By Freakzoyd in forum New To Java
    Replies: 4
    Last Post: 11-12-2010, 05:27 AM
  5. ArrayList of ArrayLists
    By coolnfunky_raj in forum New To Java
    Replies: 10
    Last Post: 07-03-2008, 11:07 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
  •