Fill a array with List data with one more element
- by marionmaiden
Hello,
By a question that I made, I figured out that tho copy elements from one list to an array I just need to use the method toArray() for this.
But let's suppose I have a List with n objects. I want to copy then into a array sized n+1 and add into the first position another object and in the other n positions the n data of the list.
This is the way I'm doing it for now, but I'm just wondering if there is a better way for do that:
Object array[] = new Object[list.size() + 1];
Object chk = new Object();
array[0] = chk;
for(int i = 1; i < array.length; i++){
array[i] = list.get(i);
}