🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.api
Article #1805

Re: Help with Boolean.valueOf

#1805
From: Holger Stratmann
Date: Wed, 12 Sep 2001 23:54
68 lines
2931 bytes
> Or you can do something like
>
>  String result = callYourMethodHere();
>  boolean foo = result.equals("Yes") ? true : false;

hmm...
booleanExpression?true:false
is a no-op (no-operation, doesn't accomplish anything), isn't it??

how about
boolean foo = result.equals("Yes"); ?

Or, even shorter:
boolean foo = "Yes".equals(yourMethodCall(...));

(note how "false" is the "default" here (false unless you return "Yes"). You
can use foo = !"No".equals(yourMethodCall()) to make "true" the default (will
be "true" unless you return (exactly) "No")

(calling the function on "Yes" is nicer, because you don't have to worry about
null-values. Calling it on a constant might also be a little faster, but I'm
not sure about that...)

Have fun,
         Holger

P.S.: All of the above is better than calling valueOf(), because valueOf()
creates a new Boolean-OBJECT which is instantly discarded => huge overhead.
Probably won't matter much, but avoid getting bad habits *g*

Alex Colic wrote:

> Thanks
>
> Alex
> "Joi Ellis [TeamB]" <joi@aravox.com> wrote in message
> news:3b865e84_2@dnews...
> > Alex Colic <alex.colic@pop-ware.com> wrote:
> > > Hi,
> >
> > > In one of my functions I get a string back, 'Yes' or 'No'. Then I have
> to
> > > set a boolean property using that String value. I have tried
> > > Boolean.valueOf(theString).booleanValue but I always get false returned
> to
> > > me.
> >
> > > Is there a simpler way of doing this?
> >
> > Try passing back 'true' and 'false' instead of 'Yes' and 'No'.
> >
> > Or you can do something like
> >
> >  String result = callYourMethodHere();
> >  boolean foo = result.equals("Yes") ? true : false;
> >
> >
> > --
> > Joi Ellis (TeamB)               http://www.teamb.com/

--

                       \\///
                      ('O O')
--------------------ooO-(_)-Ooo--------------------
Holger Stratmann
mailto:Holger@cheerful.com
---------------------------------------------------
Technical Details
Message-ID: <3B9FF5A9.2CEE23B@cheerful.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!news.tele.dk!small.news.tele.dk!130.133.1.3!fu-berlin.de!news.boerde.de!dnews
References: <3b865d98$1_2@dnews> <3b865e84_2@dnews> <3b8a77a0_1@dnews>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 1089d0,e516bf82fe973e53
X-Google-Attributes: gid1089d0,public
X-Google-ArrivalTime: 2001-09-12 15:59:19 PST
Message-ID: <3B9FF5A9.2CEE23B@cheerful.com>
Date: Thu, 13 Sep 2001 01:54:17 +0200
From: Holger Stratmann <Holger@cheerful.com>
X-Mailer: Mozilla 4.72 [en] (WinNT; U)
X-Accept-Language: en
MIME-Version: 1.0
Newsgroups: borland.public.jbuilder.java.api
To: Alex Colic <alex.colic@pop-ware.com>
Subject: Re: Help with Boolean.valueOf
References: <3b865d98$1_2@dnews> <3b865e84_2@dnews> <3b8a77a0_1@dnews>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 62.180.215.69
X-Trace: dnews 1000335254 62.180.215.69 (12 Sep 2001 15:54:14 -0700)
Lines: 70
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!news.tele.dk!small.news.tele.dk!130.133.1.3!fu-berlin.de!news.boerde.de!dnews