You can Convert a String object to Boolean object or boolean primitive by using the Boolean.valueOf() and Boolean.parseBoolean() method. The steps are similar rot converting to String to other data types e.g. String to Integer and String to Long. You can use valueOf() method to convert String to Boolean object and parseBoolean() method to convert given String to boolean primitive value. Internally, valueOf() also uses parseBoolean() for parsing String but on top of that it also provides caching e.g. it can return Boolean.TRUE and Boolean.FALSE cached value for "true" and "false" string. In fact, the Boolean.TRUE is returned only when String is equal to true ignoring case e.g. "True", "true", "TRUE" will evaluate into boolean true, hence Boolean.TRUE will be returned. For string like "Yes", Boolean.FALSE will be returned. We'll discuss the rules of String to boolean conversion in next section.
This post first appeared on Javarevisited: Blog About Java Programmin, please read the originial post: here