I have an array list like this and i would like to get the value of the key "Total" for the Product Name - Leisure 1 but not sure how to search or iterate through an array list of objects in Java spring boot
"priceList": [
{
"Total": "10",
"Stamp Duty": "10",
"Main Policy": "0",
"Product Name": "Leisure 1"
},
{
"Total": "10",
"Stamp Duty": "10",
"Main Policy": "0",
"Product Name": "Leisure 2"
},
{
"Total": "10",
"Stamp Duty": "10",
"Main Policy": "0",
"Product Name": "Leisure 3"
},
{
"Total": "10",
"Stamp Duty": "10",
"Main Policy": "0",
"Product Name": "Work 1"
},
{
"Total": "10",
"Stamp Duty": "10",
"Main Policy": "0",
"Product Name": "Work 2"
}
]
i tried doing this. I created a function
public static <K, V> Stream<K> keys(Map<K, V> map, V value) {
return map
.entrySet()
.stream()
.filter(entry -> value.equals(entry.getValue()))
.map(Map.Entry::getKey);
}
Then i tried to cast my array list to a map and tried to filter through the list to find the exact object but to no avail
priceList.stream().map(x -> x.get("Total").toString()).filter(s -> s.get("Product Name") == planHeader).collect(Collectors.toList());
How can i be able to loop through or search through an array of objects and filter by a specific value?
Any help appreciated