Understanding the bidirectional iteration of java-9.6 Listiterator from the beginning

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.