[英]how to iterate over 2 array list
I have java object containing one more object . 我有java对象包含一个对象。
public class ParameterValue {
private Property property;
private String PropertyValue;
public static class Property {
private String paramName;
}
}
In my util method i get all the property names in a list 在我的util方法中,我获取列表中的所有属性名称
List<ParameterValue.Property> properties= getAllParameter();
List<ParameterValue> paramValues= getAllParameterValues();
which returns me only ParameterValue
objets only values are set. 只返回ParameterValue
objets只设置值。
Now i want to get Property object from properties list and set in paramvalues list creating a full object. 现在我想从属性列表中获取Property对象,并在paramvalues列表中设置创建一个完整的对象。 How can i do it. 我该怎么做。 Is it possible to iterate over 2 lists 是否可以迭代2个列表
If the corresponding entry at index N
in properties
list corresponds to the same index N
in paramValues
list you can iterate using an int
counter and use List.get()
: 如果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);
}
use the standard forloop: 使用标准forloop:
for (int i = 0; i < properties.size(); i++) {
properties.get(i); //get the ParameterValue.Property
paramValues.get(i); //get the ParmeterValue
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.