Scala – Options (Some or None)




// Scala - Options (Some or None)
object Demo {
  val lst = List(1, 2, 3);
  val map = Map(1 -> "Tom", 2 -> "Max", 3 -> "John");
  val opt : Option[Int] = Some(55);
	def main(args: Array[String]) {
	  println(lst.find(_ > 2).getOrElse(0));
	  println(map.get(5).getOrElse("No_name_found"));
	  
	  println(opt.isEmpty)
	  println(opt.get)

	}
}


/*
3
No_name_found
false
55

*/

 


Partner Sites

VideoToGifs.com

EasyOnlineConverter.com

SqliteTutorials.com





Be the first to comment

Leave a Reply

Your email address will not be published.


*