zzztimbo
zzztimbo

Reputation: 2353

Is there a way to handle quoted null String in Scala?

I would like to have the String, "null" converted to an Option[String] = None.

Upvotes: 0

Views: 75

Answers (2)

Rohit Mukherjee
Rohit Mukherjee

Reputation: 21

Alternatively,

    def convertToOption(value: String): Option[String] = {
          value match {
            case "null" => None
            case  _ => Some(value)
      }
   }

Upvotes: 0

Alvaro Carrasco
Alvaro Carrasco

Reputation: 6182

val x = "null" 
Option(x).filter(_!="null")

Upvotes: 5

Related Questions