This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 10175

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: 3432
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
Similar Threads
Removing specific character from the given String
Removing single quotes from the string
String handling
comparing Strings
String class