Convert a generic list to an array

This is due to type erasure. The generics are removed in compilation, thus the Helper.toArray will be compiled into returning an Object[].

For this particular case, I suggest you use List.toArray(T[]).

String[] array = list.toArray(new String[list.size()]);

Leave a Comment