I have coded the following to add elements to the empty list using the 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();
}
I want to add elements to this empty list using the listIterator and then after adding all the elements I want to move the iterator to the beginning of the list and I also want to be able to remove the elements where the iterator points, for some reason my method doesn't seem to work, kindly help.