Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check to see if String exists in List<Map<String, String>>

Tags:

java

java-8

If I have a List<Map<String, String>> object such as this tempNameMapList:

0
   0 = "id" -> 101
   1 = "name" -> jonathan
1
   0 = "id" -> 102
   1 = "name" -> sam
2
   0 = "id" -> 103
   1 = "name" -> tim

And a String object such as String name = "tim", how would I quickly check that it exists in tempNameMapList?

like image 844
methuselah Avatar asked Mar 01 '26 02:03

methuselah


1 Answers

One possible solution using Java 8 anyMatch(...):

boolean exists = tempNameMapList.stream().anyMatch(map -> map.containsValue("tim"));
like image 119
Oleksandr Pyrohov Avatar answered Mar 02 '26 14:03

Oleksandr Pyrohov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!