query regarding Boolean.getBoolean()

I have a field say "a" which is of Type String

But when I do getBoolean of tht String(which has value true), i still get as "false"

String a = "true";

System.out.println("get Boolean of a : " + Boolean.getBoolean(a));

get Boolean of a : false

My query is , even if the String a has value "true", why is the getBoolean returning false?

[371 byte] By [swati_pekama] at [2007-11-27 8:49:12]
# 1
> > My query is , even if the String a has value "true",> why is the getBoolean returning false?Because that method doesn't do anything like you think it does which is easily descernible from looking at the API Javadocs.
cotton.ma at 2007-7-12 20:58:00 > top of Java-index,Java Essentials,Java Programming...
# 2

For ur required result

Try this one

System.setProperty("a","true");

System.out.println("get Boolean of a : " + Boolean.getBoolean("a"));

Plz Note that

It returns true if and only if the system property named by the argument exists

OnlyForJavaa at 2007-7-12 20:58:00 > top of Java-index,Java Essentials,Java Programming...
# 3
And if u dont want to use system property , use Boolean.parseBoolean() instead
SidGatea at 2007-7-12 20:58:00 > top of Java-index,Java Essentials,Java Programming...
# 4
thanks all for your responses.Actually I am using java 1.4, so Boolean.parseBoolean() is not available in tht version(its avaialble in java1.5)String a = "true";Boolean.valueOf(a).booleanValue();wud do the work.
swati_pekama at 2007-7-12 20:58:00 > top of Java-index,Java Essentials,Java Programming...