Java Iterable interface and IteratorJava Iterable interface and Iterator iterator Iterator
The interface is defined as follows:
public interface Iterator
{ boolean hasNext(); E next(); void remove();}
This interface only contains
Java.lang.IterableJava.util.IteratorIterator is an iterator class, and iterable is an interface.Many classes implement the Iterable interface so that the object can call the iterator () method.are generally used in combination, such asThe HashMap
Total: Java provides a relatively complete set of container classes, the basic types are: List, set, Queue, Map, these object types are called collection classes.one, interface inheritance relationship:Iterable interface, in Java.lang package,
Definition of iterable:Java.lang Bag/** * Implementing this interface allows a object to be the target of * the "foreach" statement. * * @param The type of elements returned by the iterator * * @since 1.5 */public interface iterable {
/** *
1. iterator is an iterator class, and iterable is designed to iterate by using foreach as long as the interface is implemented.
2. the iterator interface is encapsulated in iterable, and iterator iterators can be used as long as the class of the
Ext.: http://blog.csdn.net/zq602316498/article/details/39337899traversing a collection with iterator modeThe iterator pattern is the standard access method used to traverse the collection class. It abstracts the access logic from different types of
traversing a collection with iterator modeThe iterator pattern is a standard access method for traversing collection classes. It abstracts the access logic from different types of collection classes, thus avoiding exposing the internal structure of
The Java Collection class library separates the interfaces and implementations of the set. The same interface can be implemented differently.
The basic interface of the Java Collection class is the collection interface. The collection interface must
Traverse a set in iterator Mode
The iterator mode is a standard access method used to traverse collection classes. It canThe access logic is abstracted from collection classes of the same type to avoid exposing the internal structure of the set to
Refer to official Documentation:1 Iterable is an object that can return its members . Includes sequence types (list,str,tuple) and not-sequence types (dict, file objects), objects and classed defined with an __iter__ ( ) method or a __getitem__ ()
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.