How to check if a map contain a empty string value in scala? -
i have newbie question.
we can use contains check if map contain specified key, as:
val map = map("a"->"1", "b"->"") map.contains("a") but now, want check if map contains empty string, there method use?
try
map.values.exists(_ == "") edit: think above clearest, can't resist showing 2 others.
map.exists(_._2 == "") is more compact, have remember _2 value when iterate through map.
map.values.exists(""==) is alternative form of original, instead of explicitly comparing argument _ == "", supply equality function "".equals _ or ""== short. (two ways of looking @ same thing--is empty string supplying equals method testing, or closure testing elements against empty string? think latter (the original) considerably clearer.)
Comments
Post a Comment