How to convert String object to Boolean object?
How to convert String object to Boolean object?
Well, as now in Jan, 2018, the best way for this is to use apache's BooleanUtils.toBoolean.
This will convert any boolean like string to boolean, e.g. Y, yes, true, N, no, false, etc.
Really handy!
We created soyuz-to library to simplify this problem (convert X to Y). It's just a set of SO answers for similar questions. This might be strange to use the library for such a simple problem, but it really helps in a lot of similar cases.
import io.thedocs.soyuz.to;
Boolean aBoolean = to.Boolean("true");
Please check it - it's very simple and has a lot of other useful features
boolean status=false;
if (variable.equalsIgnoreCase("true")) {
status=true;
}
This is supported only if the string is 'true' (not case-sensitive). Later you can play with the status variable.