首页 > 解决方案 > 循环嵌套列表 RxJava2

问题描述

我有一个对象 A 的列表,并且在每个 AI 中都有一个对象 B 的列表。

这是我想做的:

List<A>使用 RxJava 循环时,我希望能够循环内部列表并List<B>在最后对 and 进行一些过滤,我想将过滤List<B>后的List<A>.

在不破坏链条的情况下可以进行此操作吗?

像这个例子:

class A {
        int mAId;
        List<B> mBList;
    }

    class B{
        int mId;
    }

    public void loop(List<A> list){
        Observable.fromIterable(list)
                .flatMapIterable(objs-> objs.mBList)
                .filter("filtering each b")
                .toList()
                .map("add back the list of b to the right a")
                .subscribe()
    }

标签: javaandroidrx-java2

解决方案


我的意见:

    public void loop(List<A> list){
     List<FromObject> innerList;
     list.forEach(e->{
      innerList=e.getInnerList();
      innerList.forEach(in->{
      <apply your filter here>
      <for example>
       if(in.getNumber()>0)
        innerList.remove(in);
      }
     }
    }

希望它会有所帮助


推荐阅读