我想java.util.LinkedList<Integer>
使用可用的方法来反转 a。
查看提供的方法,Iterators
我看不到以下选项:
int i = list.size();
int pos = 0;
while(i-- > 1){
Integer n = list.removeLast();
list.add(pos++, n);
}
但肯定有更好的方法。我的意思是在迭代器之外修改列表不是一个好主意,但我不知道如何在此处使用它而不必创建新列表。
有没有更好的办法?