I've got a questions about Collections.class and "copy" method.
1) Why we are checking size of a source list in second if conditional on below code and why it is must be less than 10? Why is it so important?
2) What is more, why we are using for loop in this conditional instead while - while (hasNext())
public static <T> void copy(List<? super T> dest, List<? extends T> src) {
int srcSize = src.size();
if (srcSize > dest.size()) {
throw new IndexOutOfBoundsException("Source does not fit in dest");
} else {
if (srcSize < 10 || src instanceof RandomAccess && dest instanceof RandomAccess) {
for (int i = 0; i < srcSize; ++i) {
dest.set(i, src.get(i));
}
} else {
ListIterator<? super T> di = dest.listIterator();
ListIterator<? extends T> si = src.listIterator();
for (int i = 0; i < srcSize; ++i) {
di.next();
di.set(si.next());
}
}
}
}
Why we are using