tags:

views:

440

answers:

2

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?

+1  A: 

Note: Don't write new Boolean(myString) in Java - always use Boolean.valueOf(myString). Using the new variant unnecessarily creates a Boolean object; using the valueOf variant doesn't do this.

Jesper
Very true. I've edited the question and removed <code>new Boolean(String)</code>.
David Crawshaw
+4  A: 

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

David Crawshaw