How to have List Iterator start at a given index?

前端 未结 3 1432
予麋鹿
予麋鹿 2021-01-14 12:45

I have a linked list and I need to make method that returns an iterator at a given point in the list. I currently have an iterator that starts at the head:

p         


        
3条回答
  •  星月不相逢
    2021-01-14 13:18

    Simply use the listIterator(index); method from List, in which index is an int resembling the starting index. Edit: in your case it would be

    List<...> list = ...;
    return list.listIterator(x);
    

提交回复
热议问题