#collections #options #scala
use getOrElse() to access a value or a default when no value is present:
If you want to change selection, open document below and click on "Move attachment"
Scala Optionsproduces the following result:
C:/>scalac Test.scala
C:/>scala Test
show(capitals.get( "Japan")) : Tokyo
show(capitals.get( "India")) : ?
C:/>
Using getOrElse() Method:
Following is the example of showing how to <span>use getOrElse() to access a value or a default when no value is present:
object Test {
def main(args: Array[String]) {
val a:Option[Int] = Some(5)
val b:Option[Int] = None
println("a.getOrElse(0): " + a.getOrElse(0) )
Summary
status | not read | | reprioritisations | |
---|
last reprioritisation on | | | suggested re-reading day | |
---|
started reading on | | | finished reading on | |
---|
Details