27 Collections - Accessing Elements
- You can access the elements of Arrays, Lists Maps and Sets using
()
- For Maps, accessing a key that doesn’t exist throws an exception:
java.util.NoSuchElementException: key not found
to check if a key exists usemap.contains(key)
or use a default value:map.getOrElse(key, defaultValue)