I have 2 arraylist as below where I have to combine the array to get all the values in the new array list where the uuid will be common in both of the lists , the final list should have all the values associated witht he UUID in the both arraylist
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"
}
]
I have to combine 2 array lists with unique "UUID", the array should look like
[
{
"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"
}
]
can I iterate the array as below ?
for(listItem1 in arraylist1){ //assuming I am storing the arraylist in variable arraylist1
for (listitem2 in arraylist2){
if(listItem1.uuid=== listItem2.uuid){
listItem = "" //assign values
}
}
}
how to create the 3rd array list and store the items in the arraylist
listItem = { ...listItem1, ...listItem2 }?