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

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -