Below is the method add() of Java List Interface; if I loop through it 7 times adding i to the 0th position like so.
for (int i = 0; i < 7; i++) {
list.add(0, i);
}
Wouldn't it overwrite the value at that position, so I would end up with just one value of 6 in the list? Am I right, in assuming that?
解决方案
No, if you add at a position, it shifts everything starting at that position to the right.
So if you actually did this, you should end up with the following list:
[6, 5, 4, 3, 2, 1, 0]
Or better yet, give it an actual try.