generics - How to dynamically initialize the size of an array of linked lists java -


i have constructor specifies how large array of linked lists should having troubles initializing size of array. i'm trying error whenever try initializing array:

// constructor

myconstruct(int initsize){     hashtable = (linkedlist<t>[]) new object[initsize]; } 

error: java.lang.object; cannot cast [ljava.util.linkedlist;

how create array of linked lists in like:

for(int = 0; < hashtable.size(); i++){     hashtable[i].add(i + i); } 

this would work:

myconstruct(int initsize){     hashtable = new linkedlist[initsize]; } 

but really, use list of lists!

myconstruct(int initsize){     hashtable = new linkedlist<linkedlist<t>>(); } 

Comments