File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Regarding String to Boolean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Regarding String to Boolean" Watch "Regarding String to Boolean" New topic

Regarding String to Boolean

surya.raaj prakash
Ranch Hand

Joined: Oct 30, 2009
Posts: 76
Hi Friends,

why In preceding code it always gives false even i pass null value?
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10828

From the API docs
The boolean returned represents the value true if the string argument is not null and is equal, ignoring case, to the string "true".

As you can see, anything else besides "true", including null generates false.

[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Joanne Neal

Joined: Aug 05, 2005
Posts: 3742
surya.raaj prakash wrote:why In preceding code it always gives false even i pass null value?

Because that's how the method works. If you pass anything other than a string containing the value "true" (ignoring case) the method returns false.

I agree. Here's the link:
subject: Regarding String to Boolean
It's not a secret anymore!