Exception in thread "main" java.lang.ClassCastException: [I
at ArrayTest.main(ArrayTest.java:7)
Mohamed Sanaulla | My Blog | Author of Java 9 Cookbook | Java 11 Cookbook
Theodore David Williams wrote:If I do thisWhat I get is a list of arrays
Theodore David Williams wrote:You can do this either:
Same error even with (Integer[] cast instead of Object[]). Besides the api I am using could return an int[], byte[], double[], float[], etc....
What I get is a list of arrays (in my case a list with on element and that element is an array of primitive ints), not a list of my integer elements in the array. I do not really want to loop through the entire array and store each element in a Generic Collection because this array of data could be huge and would take to long.
Thanks for the ideas guys.....any more???
Mohamed Sanaulla | My Blog | Author of Java 9 Cookbook | Java 11 Cookbook
Mohamed Sanaulla | My Blog | Author of Java 9 Cookbook | Java 11 Cookbook
Theodore David Williams wrote:Yeah ok I was hoping that was not my only option: because then I have:
if (int[])
else if(double[])
else if(float[])
else if(byte[])
else if(char[])
and on and on and on........
Mohamed Sanaulla | My Blog | Author of Java 9 Cookbook | Java 11 Cookbook
Object data = oldUselessApi.getData();
List list;
if (data instanceof double[]) {
list = Arrays.asList((double[])data);
}
else if (data instanceof float[]) {
list = Arrays.asList((float[])data);
}
else if...
The longest recorded flight time of a chicken is 13 seconds. But that was done without this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|