David Crawshaw David Crawshaw - 2 months ago 9
Scala Question

Scala: Elegant conversion of a string into a boolean

In Java you can write

Boolean.valueOf(myString)
. However in Scala,
java.lang.Boolean
is hidden by
scala.Boolean
which lacks this function. It's easy enough to switch to using the original Java version of a boolean, but that just doesn't seem right.

So what is the one-line, canonical solution in Scala for extracting
true
from a string?

Answer

Ah, I am silly. The answer is myString.toBoolean.