jackoverflow jackoverflow - 1 month ago 10
Java Question

Java/P5: How to declare an Array of Arraylists holding FloatLists?

If I can declare an Array of FloatLists:

FloatList [][] values = new FloatList[3][3];


Why doesn’t it work to declare an Array of ArrayLists holding FloatLists like this:
ArrayList<FloatList> [][] values = new ArrayList<FloatList>() [3][3];
? OR EVEN:
ArrayList<FloatList> [][] values = new ArrayList<FloatList> [3][3]();


How can this be achieved? Will it be hard to refer to the
floats
buried deep under its crusty texture?

Answer
ArrayList<FloatList> [][] values = new ArrayList[3][3];

Basically, you're declaring that you want an object that is a 3D array of ArrayLists, and not generating actual ArrayList objects.

Afterwards, you have to instantiate each of them, so for example:

values[0][0] = new ArrayList<>();

And so on.