Q: Write a method that transforms a list into an array (don't use collections or already implemented methods in lists, make your own method)
I've come with this solution:
public static Object[] toArray(List<Object> list) {
Object[] arr = new Object[list.size()];
for (int i = 0; i < list.size(); ++i) {
arr[i] = list.get(i);
}
return arr;
}
I've read this Convert a generic list to an array, and seems like they overcomplicated the solution. Why they choose to use generics? Is there something wrong with my approach?
List<String>arg? \$\endgroup\$