Change the data in the old arraylist based on the id of the new arraylist

Viewed 37

I have 2 arraylists as follows

ArrayList 1

[
{"id": "01", "price": "5000"},
{"id": "02", "price": "6000"},
{"id": "03", "price": "2300"}
]

ArrayList 2

[
{"id": "01", "name": "nameA", "price": "0"},
{"id": "02", "name": "nameB", "price": "0" },
{"id": "03", "name": "nameB", "price": "0"}
]

the question is, how to change the contents of price in ArrayList2 to price in ArrayList1 based on id, I have tried searching on google but did not get the right results,

1 Answers

You are advised to convert the JSON character string in the array to an object, compare the object ID and set the price, modify the object attribute, and then convert the object to a JSON character string.

Related