java - Casting Object to int array doesn't work -
this question has answer here:
- casting object array integer array error 4 answers
- convert integer[] int[] array 3 answers
i reading row database using jpa, provides object 3 int values.
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
Post a Comment