Java learning notes -- iterator and java learning notes --

Source: Internet
Author: User

Java learning notes -- iterator and java learning notes --
To achieve uniform traversal of different types of containers, an iterator is used. It mainly uses two interfaces: Iterator and Iterable. The class that implements the Iterable interface indicates that this class can be traversed using the iterator, such as List and Set.Target class to be traversed. The class that implements the Iterator interface indicates that this class is a specific class (such as List, Set)Iterator classTo traverse the target class. The class that implements the Iterable <T> interface must implement the following methods. Methods that implement this interface can be traversed using Foreach.

Iterator <T> iterator ();

This method returns a class that implements the Iterator interface for traversal.

The class implementing the Iterator <E> interface must implement the following three methods to traverse the specific class. This class can be used to return values of the previous method.
Boolean hasNext (); E next (); void remove ();

 

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.