In the below mentioned program array is a List passed as an argument to this function. The task is to cut the array into lists of LookupTable of defined size and then add them into binlists. In this case what should be the declaration of binlists? Should it be List ? Because either way it gives me an error at the add() function. It works totally fine if I use all the Lists mentioned as raw type. But my intention is to make it parametric.
protected List<LookupTable> binlists;
binlists = new ArrayList<LookupTable>(nofbins);
while(chunk+binsize <= tot_size)
{
List tempsort = (List<LookupTable>)arry.subList(chunk,chunk+binsize);
System.out.println(tempsort.size());
binlists.add(tempsort);
chunk = chunk+binsize;
}
You need to use
addAllmethod to add a list to an existing list: –And you should always declare your
Listto be ofgeneric type.So, declare your
tempSortlist as ageneric listof typeLookUpTable: –In fact, you can save yourself from that
typecastif you declare yourarrylist too as generic type.