jackoverflow jackoverflow - 5 months ago 27
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];
ArrayList<FloatList> [][] values = new ArrayList<FloatList> [3][3]();

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

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.