I suppose that
val someMap = ListMap[String,String]("key1" -> "")
is a typo, and you really meant:
val someMap = Map[String,String]("key1" -> "")
The reason you get different results is because get(key) on maps returns Option . If the specified key is stored in Map , calling map.get(key) returns Some(<value_for_given_key>) . If this key is not stored in Map , calling map.get(key) returns None .
In your example, you store the value "with the key" key1 "in someMap . Therefore, if you call someMap.get("key1") , you get Some("") . Then you call toString on that value, which returns "Some()" . And "Some()".isEmpty() returns false for obvious reasons.
source share