Java Convert String to booleanWe can convert String to boolean in java using Boolean.parseBoolean(string) method. To convert String into Boolean object, we can use Boolean.valueOf(string) method which returns instance of Boolean class. To get boolean true, string must contain "true". Here, case is ignored. So, "true" or "TRUE" will return boolean true. Any other string value except "true" returns boolean false. Java String to boolean Example: Boolean.parseBoolean()The parseBoolean() method converts string into boolean primitive. The parseBoolean() is the static method of Boolean class. The signature of parseBoolean() method is given below: Let's see the simple example of converting String to boolean in java. Test it NowOutput: true true false Java String to Boolean Example: Boolean.valueOf()The Boolean.valueOf() method converts string into Boolean object. Let's see the simple code to convert String to Boolean in java. Test it NowOutput: true true false Next TopicJava boolean to String |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India