我已经使用RxJava 1已有一段时间了,但我想看看RxJava2。在RxJava 1中,我可以发出列表的每个项目,如下所示:
List<String> list = ...
Observable.from(list)
.filter(str -> str.contains("Help")
.subscribe(...);
但是,如何使用RxJava2实现相同的目的?我尝试使用以下内容,但似乎无法通过以下内容:
Observable.fromArray(list)
// this now passes a list into the stream - there is no Observable::from
你需要使用fromIterable()
,因为任何List<T>
扩展Collection<T>
延伸Iterable<T>
Observable.fromIterable(list)
.filter(str -> str.contains("Help")
.subscribe(...);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句