简体   繁体   中英

how to iterate over 2 array list

I have java object containing one more object .

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

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

which returns me only ParameterValue objets only values are set.

Now i want to get Property object from properties list and set in paramvalues list creating a full object. How can i do it. Is it possible to iterate over 2 lists

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() :

// 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:

for (int i = 0; i < properties.size(); i++) {
  properties.get(i); //get the ParameterValue.Property
  paramValues.get(i); //get the ParmeterValue
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM