如何从数组中获取数组

时间:2019-10-16 10:31:42

标签: groovy

我有一个数组

Object[][] arrays= [
    [country:USA, history:N, state:IL, zip:61523, phone:3090000000, id:3358897, lastName:BOYLE, billing:Y, address2:null, firstName:PAUL F , email:energyroofing1@XyZ, address1:PO BOX 507, city:CHILLICOTHE],
    [country:USA, history:N, state:IL, zip:61523, phone:3090000000, id:6372385, lastName:BOYLE, billing:N, address2:null, firstName:PAUL F , email:energyroofing1@xyz, address1:PO BOX 507, city:CHILLICOTHE]
]

作为回报,我要有帐单的数组:Y

1 个答案:

答案 0 :(得分:0)

您的问题不清楚。另外,您的数据似乎是地图的数组,而不是数组的数组,除非子数组实际上包含例如文字字符串“ country:USA”的元素?

但是,假设您要的是一个数组,其中包含billing设置为Y的原始数组中的所有映射,那么您可以这样做:

def arrays = [
    [country:"USA", history:"N", state:"IL", zip:"61523", billing:"Y" ],
    [country:"USA", history:"N", state:"CA", zip:"61999", billing:"N" ]
]

def billingSetToY = arrays.grep { it["billing"] == 'Y' }

assert billingSetToY.size() == 1
assert billingSetToY[0]["state"] == "IL"

如果您正在寻找其他东西,请编辑您的问题以澄清它。