我已經編寫了以下使用的ListIterator將元素添加到空表:如何使用ListIterator將元素添加到空列表中?
ArrayList<String> list = new ArrayList<String>();
ListIterator<String> listIterator = list.listIterator();
public void append(String... tokens) {
if(tokens == null)
return;
// append tokens at the end of the stream using the list iterator
for(int i = 0 ; i < tokens.length ; ++i){
// if the token is not null we append it
if(tokens[i] != null && !tokens[i].equals(""))
listIterator.add(tokens[i]);
}
reset();
}
我要添加使用的ListIterator元素到此空列表,然後將所有的元素後,我想移動的迭代器到列表的開頭,我也希望能夠刪除迭代器指向的元素,出於某種原因,我的方法似乎不工作,請幫助。
其實我是想爲什麼我使用的ListIterator – AnkitSablok
你能具體談談什麼是不工作添加使用的ListIterator避免ConcurrentModificationException的元素的迭代器,那是什麼?一個可能的錯誤(可能是它的意圖)是++,而不是i ++。 –