Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Rxjava中通过键合并两个可观察的对象?_Java_Android_Rx Java_Reactive Programming_Rx Android - Fatal编程技术网

如何在Rxjava中通过键合并两个可观察的对象?

如何在Rxjava中通过键合并两个可观察的对象?,java,android,rx-java,reactive-programming,rx-android,Java,Android,Rx Java,Reactive Programming,Rx Android,我有一个可观察到的a class User { public int userId; public String userName; public int age; public Boolean vip; } 数据集: userId userName age vip 1 ham 21 false 2 lily 18 false 3 potter 38 false userId

我有一个可观察到的a

class User {
    public int userId;
    public String userName;
    public int age;
    public Boolean vip;
}
数据集:

userId  userName  age   vip
   1       ham     21  false
   2       lily    18  false
   3       potter  38  false
userId  vip
   1   true
可观测b

class VIP {
    public int userId;
    public Boolean vip;
}
数据集:

userId  userName  age   vip
   1       ham     21  false
   2       lily    18  false
   3       potter  38  false
userId  vip
   1   true
预期的合并结果:

userId  userName  age   vip
   1       ham     21  true
   2       lily    18  false
   3       potter  38  false

众所周知,Rxjava有
Merge
Concat
Zip
Join
,但它们似乎都无法做到这一点

如果两个流的用户顺序相同,那么您可以
Zip
它们:

users.zipWith(vips, (u,v) -> new User(u.userName, u.userId, u.age, v.vip))
您可以修改
u
,但最好选择不变性(因此创建一个新对象)

如果两个流的顺序不同,可以使用中的
matchWith
from