Results 1 to 2 of 2
  1. #1
    ilayaraja is offline Member
    Join Date
    Oct 2009
    Posts
    1
    Rep Power
    0

    Default how to create list of list in java ???

    i want make List to List<List<List>>


    class IdentClass{

    Integer testIdent;
    Integer partIdent;
    Integer itemIdent;

    public IdentClass(Integer testIdent,Integer partIdent,Integer itemIdent){

    this.testIdent = testIdent;
    this.partIdent = partIdent;
    this.itemIdent = itemIdent;
    }

    }

    public class Test{
    List identList = new ArrayList();
    for(IdentClass i : identList)
    System.out.println(i.testIdent+"\t"+i.partIdent+"\ t"+i.itemIdent);
    }

    my output :

    //test part item
    1 12 31
    1 23 12
    1 23 15
    1 23 17
    1 97 28
    1 97 35
    1 97 52
    2 65 1
    2 65 26
    2 65 37
    2 82 22
    3 11 27
    3 11 28
    3 12 31
    3 12 33
    3 65 32
    3 74 26

    i have a identList which prints above output in sorted order.

    but i need testList in below format :

    List<List<List>> testList = new ArrayList<List<List>>();

    for(List<List> partList : testList){ // for test
    for(List itemList : partList){ // for part
    for(IdentClass i : itemList){ // for item
    System.out.println(i.testIdent+"\t"+i.partIdent+"\ t"+i.itemIdent);
    }
    }
    }

    my question is how to make this testList ??

  2. #2
    literallyjer is offline Member
    Join Date
    Oct 2009
    Posts
    25
    Rep Power
    0

    Default

    You can't use interfaces when declaring the generic lists.

    Arraylist<ArrayList<String>> listOfListOfStrings = new ArrayList<ArrayList<String>>();

    or

    List<ArrayList<String>> listOfListOfStrings = new ArrayList<ArrayList<String>>();

    You probably could use the unknown type (?) but the deeper you dive into generics, the harder the code is to write/maintain.

    http://java.sun.com/j2se/1.5/pdf/generics-tutorial.pdf

    EDIT: This works...

    ArrayList<? extends List<?>> list = new ArrayList<ArrayList<String>>();
    Last edited by literallyjer; 10-26-2009 at 05:33 PM.

Similar Threads

  1. Linked List integer list
    By igniteflow in forum Advanced Java
    Replies: 1
    Last Post: 12-10-2008, 09:53 PM
  2. How to access ArrayList in List of List?
    By alvations in forum New To Java
    Replies: 5
    Last Post: 10-08-2008, 01:23 PM
  3. How to Search a List in Java
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-16-2008, 11:38 PM
  4. How to create a Sorted List in Java
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-16-2008, 11:31 PM
  5. Replies: 20
    Last Post: 12-17-2007, 04:20 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
  •