Ich habe eine Klasse namens Grid
erstellt und ich struggeling, um die Kapazität eines verschachtelten ArrayList
zu definieren. Dies ist, was ich derzeit haben:Definieren der Kapazität einer mehrdimensionalen Arraylist
public class Grid extends GameObject {
private int cols;
private int rows;
private int colWidth;
private int rowHeight;
private ArrayList<ArrayList<GameObject>> contents;
public Grid(int x, int y, int cols, int rows, int colWidth, int rowHeight, ID id) {
super();
this.x = x;
this.y = y;
this.cols = cols;
this.rows = rows;
this.colWidth = colWidth;
this.rowHeight = rowHeight;
//Here I want to define the contents
this.width = colWidth * cols;
this.height = rowHeight * rows;
this.id = id;
}
}
Der Code sollte wie folgt aussehen:
this.contents = new ArrayList<ArrayList<GameObject>(cols)>(rows);
Aber dies gibt einen Fehler. Kann jemand dieses Problem lösen, ich würde es wirklich schätzen! Danke im Voraus!
Ich hoffte irgendwie, dass es möglich war, aber das wird reichen müssen. Danke! – Trashtalk