In this chapter we will briefly discuss the Listiterator.
Listiterator is mainly to supplement the iterator can only backward problems, in the listiterator can move forward.
Package Com.ray.ch09;import Java.util.arraylist;import Java.util.listiterator;public class Test {public static void Main (string[] args) {arraylist<integer> ArrayList = new arraylist<integer> (); for (int i = 0; i < i++) { Arraylist.add (i);} Listiterator<integer> iterator = Arraylist.listiterator (); while (Iterator.hasnext ()) {Integer RTN = Iterator.next (); System.out.print (RTN);} System.out.println (); while (Iterator.hasprevious ()) {Integer RTN = iterator.previous (); System.out.print (RTN);}}}
Output:
0123456789
9876543210
Note: You must detect the authenticity of iterator.hasprevious () before using iterator.previous (), or throw an exception when the first element is not pressed into the iterator.
Summary: This chapter briefly describes the bidirectional iterations of the Listiterator.
This chapter is here, thank you.
-----------------------------------
Directory
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Understanding the bidirectional iteration of java-9.6 Listiterator from the beginning