Posted By: Anonymous
How to convert
String object to
Try (depending on what result type you want):
Boolean boolean1 = Boolean.valueOf("true"); boolean boolean2 = Boolean.parseBoolean("true");
- Boolean: this does not create new instances of Boolean, so performance is better (and less garbage-collection). It reuses the two instances of either
- boolean: no instance is needed, you use the primitive type.
The official documentation is in the Javadoc.
Autoboxing could also be used, but it has a performance cost.
I suggest to use it only when you would have to cast yourself, not when the cast is avoidable.