您好,登錄后才能下訂單哦!
小編給大家分享一下java中如何實現生成器和迭代器,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
print([ i*2 i range(10)]) print(range(10)) print(( i*2 i range(10))) b=( i*2 i range(10)) print(b.__next__()) fib(max): n,a,b = 0,0,1 n<max: print(b) a,b=b,a+b n=n+1 fib(10) fib(max): n,a,b = 0,0,1 n<max: b a,b=b,a+b n=n+1 f = fib(10) print(fib(10)) g=fib(10) : : x=next(g) print(,x) StopIteration e: print(, e.value) print(f.__next__()) print() print(f.__next__()) print(f.__next__()) print() print(f.__next__()) print(f.__next__()) print(f.__next__()) print(f.__next__()) print(f.__next__()) print(f.__next__()) print(f.__next__()) print(f.__next__()) time consumer(name): print(%name) : baozi = print(%(baozi,name)) c = consumer() c.__next__() b1 =c.send(b1) c.__next__() time consumer(name): print(%name) : baozi = print(%(baozi,name)) producer(name): c = consumer() c2 = consumer() c.__next__() c2.__next__() print() i range(10): time.sleep(1) print() c.send(i) c2.send(i) producer() collections Iterable print(isinstance([],Iterable)) print(isinstance(,Iterable)) print(isinstance({},Iterable)) print(isinstance((),Iterable)) print(isinstance(100,Iterable)) collections Iterator a=[1,2,3] print(isinstance((x x range(5)),Iterator)) print(isinstance([],Iterator)) print(isinstance({},Iterator)) print(isinstance(,Iterator)) b = [1,2,3] a=iter(b) print(a.__next__()) print(a.__next__()) it = iter([1,2,3,4,5]) : : x = next(it) StopIteration:
以上是“java中如何實現生成器和迭代器”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。