我想将 divider 对象插入到集合中。
Observable<String> observable = Observable.from(new String[] { "a", "b", "c" });
Iterable<String> dividedList = observable.flatMapIterable(new Func1<String, Iterable<String>>() {
@Override public Iterable<String> call(String s) {
return Lists.newArrayList(s, "divider");
}
}).toBlocking().toIterable();
我想要["a", "divider", "b", "divider", "c"]
,
但实际上,当然是 ["a", "divider", "b", "divider", "c", "divider"]
我如何使用 RxJava 做到这一点?
最佳答案
只需使用 skipLast
运算符删除最后一个元素!
Observable.just("a", "b", "c")
.flatMap((l) -> Observable.just(l, "divider"))
.skipLast(1)
.toBlocking().toIterable();
关于java - RxJava : insert divider object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29143562/