Results 1 to 2 of 2
- 10-26-2009, 03:19 PM #1
Member
- Join Date
- Oct 2009
- Posts
- 1
- Rep Power
- 0
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 ??
- 10-26-2009, 04:30 PM #2
Member
- Join Date
- Oct 2009
- Posts
- 25
- Rep Power
- 0
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 04:33 PM.
Similar Threads
-
Linked List integer list
By igniteflow in forum Advanced JavaReplies: 1Last Post: 12-10-2008, 08:53 PM -
How to access ArrayList in List of List?
By alvations in forum New To JavaReplies: 5Last Post: 10-08-2008, 12:23 PM -
How to Search a List in Java
By Java Tip in forum java.langReplies: 0Last Post: 04-16-2008, 10:38 PM -
How to create a Sorted List in Java
By Java Tip in forum java.langReplies: 0Last Post: 04-16-2008, 10:31 PM -
can java.io.File create a list of all files and folders.
By MattStone in forum New To JavaReplies: 20Last Post: 12-17-2007, 03:20 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks