0 votes
in Scala Constructs by
Explain Option and write its usage.

1 Answer

0 votes
by

The Scala Option[T] is referred to as a carrier of one element or none for a specified type. As the name suggests, this container holds either a Some or a None object, which represents a missing value. It holds Some[T] if a value is stored, otherwise none. In simple words, Scala options are wrappers for missing values. 

Example:

 object option  

{  

      def main(args: Array[String])  

    {  

        val employee: Map("InterviewBit" -> "Aarav", "Scaler" -> "Ankesh")  

        val a= employee.get("InterviewBit")  

        val b= employee.get("Informatica")  

        println(a);  

        println(b);  

    }  

}  

Output:  

Some(Aarav)   

None  

...