I am faced with a task where I need to merge two array lists in order to create a new array list that contains all the values associated with a common UUID in both lists. The final list should include all the values linked to the UUID in each of the original array lists.
List 1:
[
{
"uuid":"01",
"plan" : "aaaa",
"other_details":"xxxxxx"
},
{
"uuid" : "02",
"plan" : "bbbb",
"other_details":"yyyyyyy"
},
{
"uuid" : "03",
"plan" : "cccc",
"other_details":"zzzzzz"
},
{
"uuid" : "04",
"plan" : "dddd",
"other_details":"uuuuuu"
}
]
List 2:
[
{
"uuid":"01",
"office" : "India",
"status":"running"
},
{
"uuid" : "02",
"office" : "USA",
"status":"running"
},
{
"uuid" : "03",
"office" : "Germany",
"status":"running"
},
{
"uuid" : "04",
"office" : "Australia",
"status":"shutdown"
}
]
The goal is to combine the two array lists using the unique "UUID" value. The resulting array should appear as follows:
[
{
"uuid":"01",
"plan" : "aaaa",
"other_details":"xxxxxx",
"office" : "India",
"status":"running"
},
{
"uuid" : "02",
"plan" : "bbbb",
"other_details":"yyyyyyy",
"office" : "USA",
"status":"running"
},
{
"uuid" : "03",
"plan" : "cccc",
"other_details":"zzzzzz",
"office" : "Germany",
"status":"running"
},
{
"uuid" : "04",
"plan" : "dddd",
"other_details":"uuuuuu",
"office" : "Australia",
"status":"shutdown"
}
]
Is it possible to iterate through the array like this?
for(listItem1 in arraylist1){
for (listitem2 in arraylist2){
if(listItem1.uuid=== listItem2.uuid){
listItem = ""
}
}
}
How can I create the third array list and store the items in it?