There is an ArrayList al, and I want to copy the first half of its elements into another ArrayList firstHalf. (If al
ArrayList al
ArrayList firstHalf
You should use add instead of set:
add
set
int x = al.size()/2 + (al.size()%2) - 1; for(int i = 0; i < x; i++){ firstHalf.add(al.get(i)); }
It would be better to use List#subList