Iterator和ListIterator的区别?

●ListIterator有add()方法,可以向List中添加对象,而Iterator不能。

●ListIterator和Iterator都有hasNext()和next()方法,可以实现顺序向后遍历,但是ListIterator有hasPrevious()和previous()方法,可以实现逆向(顺序向前)遍历。Iterator就不可以。

●ListIterator可以定位当前的索引位置,nextIndex()和previousIndex()可以实现。Iterator没有此功能。

●都可实现删除对象,但是ListIterator可以实现对象的修改,set()方法可以实现。Iierator仅能遍历,不能修改。

posted @ 2020-05-15 01:19  咔啡  阅读(114)  评论(0编辑  收藏  举报