gpt4 book ai didi

java - 如何迭代2个数组列表

转载 作者:行者123 更新时间:2023-12-02 07:32:59 25 4
gpt4 key购买 nike

我有一个 java 对象,其中还包含一个对象。

public class ParameterValue {            
private Property property;
private String PropertyValue;
public static class Property {
private String paramName;
}
}

在我的 util 方法中,我获取列表中的所有属性名称

 List<ParameterValue.Property> properties=   getAllParameter();    
List<ParameterValue> paramValues= getAllParameterValues();

它只返回给我的ParameterValue对象,仅设置值。

现在我想从属性列表中获取属性对象,并在参数值列表中设置创建一个完整的对象。我该怎么做。是否可以迭代 2 个列表

最佳答案

如果 properties 列表中索引 N 处的相应条目对应于 paramValues 列表中相同的索引 N您可以使用 int 计数器进行迭代并使用 List.get() :

// assert properties.size() == paramValues.size();
for (int idx = 0, size = properties.size(); idx < size; idx++)
{
ParameterValue.Property prop = properties.get(idx);
ParameterValue value = paramValues.get(idx);
}

关于java - 如何迭代2个数组列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12671488/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com