How to check if String value is Boolean type in Java?

Posted by Ragnar on Stack Overflow See other posts from Stack Overflow or by Ragnar
Published on 2009-11-19T12:13:28Z Indexed on 2010/05/21 8:00 UTC
Read the original article Hit count: 172

Filed under:
|
|
|

I did a little search on this but couldn't find anything useful.

The point being that if String value is either "true" or "false" the return value should be true. In every other value it should be false.

I tried these:

String value = "false";
System.out.println("test1: " + Boolean.parseBoolean(value));
System.out.println("test2: " + Boolean.valueOf(value));
System.out.println("test3: " + Boolean.getBoolean(value));

All functions returned false :(

© Stack Overflow or respective owner

Related posts about java

Related posts about string