'How to filter and check if specific key and value exists list in List<Map<String, Object>> in java
I have JSON response as:
[{name=key1, values=[V1, V2]}, {name=key2, values=[D1, D2]}]
which is read as List<Map<String, Object>> obj in java
I need to check if "key2" exists in above obj and if yes check if value D2 exists.
Am running multiple for loops to get Object from Map and then comparing making the code quite complex
Solution 1:[1]
Your choice of the data structure is making the code complex. You can think of your json as below:
Map<String, List<Object> >
Using this data structure, you could easily use built-in methods like containsKey() to check if the key exists and then iterate over the values in List for that key and check the values.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | T.Square |
