I created a method to return a copy of List<T>
, basically I convert the List<T>
into an array T[]
, then perform the copy with the arrayCopy(T[])
method and back convert again in List<T>
.
I want to know if the code will be run successfully in different scenarios and it is good in performance or is there a way to do it better.
public static <T> List<T> getCopyOfList(List<T> list) {
return Arrays.asList((T[]) arrayCopy(list.toArray()));
}
public static <T> T[] arrayCopy(final T[] original) {
return Arrays.copyOf(original, original.length);
}