I have a newbie question.
We can use contains to check if a map contain a specified key, as:
val map = Map("a"->"1", "b"->"")
map.contains("a")
But now, I want to check if the map contains an empty string, is there any method to use?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Try
Edit: I think the above is the clearest, but I can’t resist showing two others.
is more compact, but you have to remember that _2 is the value when you iterate through a map.
is an alternative form of the original, where instead of explicitly comparing the argument with
_ == "", you supply an equality function"".equals _or""==for short. (Two ways of looking at the same thing–is it the empty string supplying its equals method for testing, or is it your closure testing the elements against the empty string? I think the latter (the original) is considerably clearer.)