java - Casting Object to int array doesn't work -


this question has answer here:

i reading row database using jpa, provides object 3 int values.

eclipse debugger

i trying cast object int[] array, throws classcastexception , says:

ljava.lang.object; cannot cast [i 

this code:

try {     utx.begin(); } catch (notsupportedexception e) {     e.printstacktrace(); } catch (systemexception e) {     e.printstacktrace(); } query q = em.createnativequery("select * mytable"); list<object> objectlist = q.getresultlist();  (int = 0; < objectlist.size(); i++) {     object object = objectlist.get(i);     int[] array = (int[]) object; } 

i tried integer[]. same exception.

does see problem? how can cast it?

just noted , there difference in int[] , integer[]. noted @anabad can follow other post. cast integer[] 1 liner , int[] need loop

object[] objectarray = new object[] { new integer("32"), new integer("11"), new integer("0") }; int[] integers = new int[objectarray.length];  integer[] objectintarray = arrays.copyof(objectarray, objectarray.length,integer[].class);   (int = 0; < objectarray.length; i++) {     integers[i] = (int) objectarray[i];// works java 7 , else                                         // use                                         // integer.parseint(objectarray[i].tostring()  } 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -