簡體   English   中英

如何迭代2個數組列表

[英]how to iterate over 2 array list

我有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 objets只設置值。

現在我想從屬性列表中獲取Property對象,並在paramvalues列表中設置創建一個完整的對象。 我該怎么做。 是否可以迭代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);
}

使用標准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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM