I have two list of object.
List<ClassA>
and List <ClassB>
. ClassA has a field TextA
and ClassB has a text field TextB
. I want to copy the TextB
value to TextA
for each object of ClassA. Any idea how to go about this?
How do I loop through both ClassB and ClassA at the same time. I though of using Map but I am not sure how to go about forming key value pair here.
Best Answer
Define a
Map<String,String>
of linked fields and iterate that instead.eg:
Then, iterate over the list of ObjectA (assuming that you want to copy the values to the corresponding ObjectB)
In the mapFields function, iterate over your mapFields, copying values: