I have a class
public class ABC {
public int i;
public float f;
public ABC(int d1,float d2) {
i=d1;
f=d2;
}
}
I have created a ArrayList of ABC object .
ArrayList<ABC> list = new ArrayList<ABC>();
ABC abc1=new ABC(1,1.0f);
ABC abc2=new ABC(2,2.0f);
list.add(abc1);
list.add(abc2);
Now I want to convert the ArrayList into array with toArray()
method, but this Method returns Object[];
.
Now I can typecast elements of Object[]
one by one into ABC type object and create ABC[];
,
but Is there any other way to typecast the Object[] into ABC[] in one command ? Something like this
ABC[] array=(ABC[])list.toArray();
though this command throws this exception
Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; can not be cast to [LABC;**
Any Help