Change the line
c=(Integer[]) list.toArray();
to
c= list.toArray(c); // add c as parameter
In your list.toArray();
returns Object[]
and
JVM doesn‘t know how to blindly downcast Object[]
to Integer[]
.
public Object[] toArray() //return Object type array
public <T> T[] toArray(T[] a) //Returns an array containing all of the elements in this collection; the runtime type of the returned array is that of the specified array