You can do it in following ways :
1.
List<List<Chemical>> listOfLists = new ArrayList<List<Chemical>>();
or other way :
2.
It may be more appropriate to use a Map<Chemical, List<Chemical>>
. Having the value of the Map as a List<Chemical>
will allow you to expand the list as opposed to an array which has a fixed size.
public static void main(String[] args) throws CloneNotSupportedException {
Map<Chemical, List<Chemical>> myMap = create(1, 3);
}
public static Map<Chemical, List<Chemical>> create(double row, double column) {
Map<Chemical, List<Chemical>> chemicalMap = new HashMap<Chemical, List<Chemical>>();
for (double x = 0; x < row; x++) {
for (double y = 0; y < column; y++) {
chemicalMap.put(x, new ArrayList<Chemical>());
}
}
return chemicalMap;
}
> listOfLists = new ArrayList
– user3145373 ツ May 31 '14 at 04:27>();