So imagine I have the following: myList of type ArrayList<CustomType> and I want to convert it to an array, how would I go about this?
I have tried
CustomType[] myArr = (CustomType)myList.toArray();
This compile, no problem but I get a casting exception at runtime. My current solution is iterating through the ArrayList and writing each entry into the array, not good.
Any idea? Thanks.
You have a version of toArray that takes a type
toArray(T[] a)
So you would do:
myList.toArray(new CompositeType[myList.size()]);
myList.toArray(new CustomType[myList.size]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With