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, Collection, List, Queue, set interface inherit Iterable interfaceAs can be seen, list, Queue, set these three interfaces are in the Java.util package, inherit from the collection interfaceThe map interface does
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 class implements the Iterable interface, and when you want to access or print all the contents of a map, you can:1 Has
function is overwritten:Listing 2. Output Fibonacci Number The first N numbers second editionDef FAB (max): N, a, b = 0, 0, 1 L = [] while n
return L
The List returned by the FAB function can be printed using the following method:>>> for N in Fab (5): ... Print N ... 1 1 2) 3 5 The rewritten fab function can meet the requirements of reusability by returning the List, but more experienced developers will point out that the memory consumed by this function will inc
Definition of iterable:Java.lang Bag/** * Implementing this interface allows a object to be the target of * the "foreach" statement. * * @param /** * Returns An iterator over a set of elements of type T. * * @return an Iterator. * /iteratorDefinition of iterator:Java.util Package:Public interface IteratorIterator is an iterator class, and iterable is designed to iterate using foreach as long as the interface is implemented.The itera
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 Iterable interface is implemented.
3. Collection collection, List, and set are all implementation classes of
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 three functions. The hasNext () and next () methods appear in our common set traversal.Functions:Use next () to obtain the next element in the sequence. Use hasN
1.1 iterable literal meaning: iterative, repeatableiterableIs the new type introduced by the ES6 standard. and Array , Map and Set all belong to the iterable type1.2 Why join a iterable type?
Traversing the array can take the subscript loop, and traversing the map and set cannot use the subscript. The collection type is not uniform.
For a loop of typ
treeiterator, but they all implement the iterator interface. So, the client doesn't care what kind of Iterator it is, it just needs to get the Iterator interface. This is the power of object-oriented.All collection classes implement the Collection interface, while Collection inherits the Iterable interface./** * Implementing this interface allows a object to be the target of * the "foreach" statement. * * @param /** * Returns An iterator over a s
be the same as the next method.Use togetherTo remove the elements returned by the next method.
package com.xujin;import java.util.ArrayList;import java.util.Collection;import java.util.Iterator;public class Test{public static void main(String...arg){Collection
Iterable Interface
The iterable interface only contains one method:
public interface Iterable
The
Python standard library: built-in function filter (function, iterable), pythoniterable
This function is used to traverse all elements from an iteration object iterable. When each element is run on the function object as a parameter, the elements that are judged to be True are retained, while those that are False are skipped, that is, to filter unnecessary elements. The
Iterable and Iterator of java. util, java. utiliterable
package java.lang;
import java.util.Iterator;public interface Iterable Iterator}
Iterable is located in the java. lang Package, which holds an Iterator reference
package java.util;public interface Iterator boolean hasNext(); E next(); void remove();}
Iterator is also an interface that contains th
Traversal Array can take the subscript loop, traverse Map and Set cannot use subscript. In order to unify collection types, the ES6 standard introduces new iterable types Array , Map and Set all of them belong to iterable types.A iterable collection with a type can traverse through a new for ... of loop.varA = [' A ', ' B ', ' C '];vars =NewSet ([' A ', ' B ', '
As long as the parameters within the extend are iterable, you can also add custom iterable, open the whole.Class A (object): def __init__ (self): self.a = 0 def __iter__ (self): return to self def next: SELF.A = self.a + 1 if SELF.A >: self.a = 0 raise stopiteration ();
1 Why are the parameters of some functions specified to Iterable object, but can also pass in list as parameter?Because list, dictionary are all iterable object.adding ITER () to the Iterable object will return a iterator.2 iterable The difference between object and iteratorIterator can use next () to traverse the acce
When you look at a function's description document, it often appears that the parameter of the function is iterable, so what does iterable mean?Iterable: An iterative, iteratorIn Python, iterable is considered an object that can return one of its members at a time (that is, the elements inside the object), so that the
may return Setiterator,tree may return treeiterator, but they all implement the iterator interface, so , the client doesn't care what kind of Iterator it is, it just needs to get the Iterator interface, which is the power of object-oriented.All collection classes implement the Collection interface, while Collection inherits the Iterable interface.[Java]View PlainCopy
/**
* Implementing this interface allows a object to be the target of
* the
JavaScript learns to record Day4-map, set, and iterable[TOC]The default object representation of JavaScript {} can be thought of as a Map data structure in another language Dictionary , or a set of key-value pairs.But the JavaScript object has a small problem, which is that the key must be a string. But actually number or other data type as a key is also very reasonable.To solve this problem, the latest ES6 specification introduces new data types Map
Python standard library: built-in function any (iterable), pythoniterable
If one of all elements of an object that can be iterated is True, True is returned. Otherwise, False is returned. Or if the iteratable object is null, False is returned. This function is mainly used to determine whether the list, tuples, dictionaries, and other objects have elements that are True, improving the computing speed. The equivalent code is as follows:
Def any (
iterator it is. It only needs to obtain this iterator interface, which is the power of object-oriented.
All collection classes implement the collection interface, while collection inherits the iterable interface.
/** * Implementing this interface allows an object to be the target of * the "foreach" statement. * * @param
In a specific implementation class (such as arraylist), an itr internal class is maintained internally, which inherits the iterat
The ES6 Standard introduces new iterable types, Array Map and all of Set them belong to iterable types. a collection of 1.for of loops with a iterable type can be traversed by a new for ... of loop. var a = [' A ', ' B ', ' C '];A.name = ' Hello ';for (var x of a) {alert (x); ' A ', ' B ', ' C '} for ... of for ... in What is the difference between loops and loop
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.