In article <457cbcec$0$49202$>, =?ISO-8859-1?Q?
Arne_Vajh=F8j?= took the hamburger meat, threw it on the grill, and I
said "Oh Wow"...
> trippy wrote:
> > In article <. com>,
> > Daniel Pitts took the hamburger meat, threw it on the grill, and I said
> > "Oh Wow"...
> >> trippy wrote:
> >>> In article <. com>,
> >>> harryajh took the hamburger meat, threw it on the grill, and I said "Oh
> >>> Wow"...
> >>>
> >>>> Which is best?
> >>>>
> >>>> String str = "hello";
> >>>>
> >>>> if("hello".equals(str))
> >>>>
> >>>> or
> >>>>
> >>>> if(str.equals("hello")
> >>>>
> >>>> does it make any difference
> >>> No.
> >>>
> >> It does make a difference if str might be null.
> >
> > Not that you won't get an NPE from either of these statements but we'll
> > play hypothetical coder just to look cool.
>
> The first will not give a NPE the second will if str is null.
Because it'll just compare "hello" to null. (in the first one)
Makes sense.
--
trippy
mhm31x9 Smeeter#29 WSD#30
sTaRShInE_mOOnBeAm aT HoTmAil dOt CoM
NP: "Heart And Soul" -- T'Pau
"Now, technology's getting better all the time and that's fine,
but most of the time all you need is a stick of gum, a pocketknife,
and a smile."
-- Robert Redford "Spy Game"
|