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

  • A+
Category:Languages

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?

 


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

boolean exists = tempNameMapList.stream().anyMatch(map -> map.containsValue("tim")); 

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: