String comparison - which way around?

?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

trippy said:
Daniel Pitts took the hamburger meat, threw it on the grill, and I said
"Oh Wow"...

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.

Arne
 
T

trippy

Arne_Vajh=F8j?= took the hamburger meat, threw it on the grill, and I
said "Oh Wow"...
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"
 
C

Chris Uppal

trippy said:
Not that you won't get an NPE from either of these statements but we'll
play hypothetical coder just to look cool.

if ("hello".equals(str)) --> "hello" != null so it'll be false.
if (str.equals("hello"))--> null != "hello" so it'll be false.

The first will return false; the second will blow up with an NPE. They are
/not/ equivalent (as this thread has already discussed at some length).

-- chris
 
T

trippy

Chris Uppal took said:
The first will return false; the second will blow up with an NPE.

Right. My bad. And thanks again to Arne for pointing that out too.
They are
/not/ equivalent (as this thread has already discussed at some length).

Yeah Trippy, you goofball. Gahd.

--
trippy
mhm31x9 Smeeter#29 WSD#30
sTaRShInE_mOOnBeAm aT HoTmAil dOt CoM

NP: "The American Way" -- Sacred Reich

"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"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top