I want to convert an array from one type to another. As shown below, I loop over all objects in the first array and cast them to the 2nd array type.
But is this the best way to do it? Is there a way that doesn't require looping and casting each item?
public MySubtype[] convertType(MyObject[] myObjectArray){
MySubtype[] subtypeArray = new MySubtype[myObjectArray.length];
for(int x=0; x < myObjectArray.length; x++){
subtypeArray[x] = (MySubtype)myObjectArray[x];
}
return subtypeArray;
}