java - List of arrays to array of arrays -
i have list of arrays of integers. want convert array of arrays of integers, when using toarray()
error [ljava.lang.object; cannot cast [[i
what doing wrong? thanks
public int[][] getcells() { list<int[]> cells = new arraylist<>(); (int y = this.y0; y <= this.y1 ; y++) { (int x = this.x0; x <= this.x1 ; x++) { cells.add(new int[]{x, y}); } } return (int[][]) cells.toarray(); }
edit
i've seen in case can convert with:
return cells.toarray(new int[cells.size()][2]);
but because integer arrays have same size (2). if don't know it? thanks
you need call
cells.toarray(new int[cells.size()][])
your old call cells.toarray()
not work since creates array of objects object[]
apparently cannot cast int[][]
Comments
Post a Comment