#!/usr/bin/env python import string, cgi, os, whrandom, pickle, sys import cgitb; cgitb.enable() #sys.path.insert(0, '/home/mu.org/home/gus/fm/fmblog') #import fmbloglib,fmblog print 'Content-type: text/html\r\n' print ''' gus mueller
How to test for string equality in java:

Generally, when a new programmer wants to check to see if the values of 2 strings are the same, the first thing he/she tries is this:
if (someString == "Yes") {
     ....
}

But that\'s wrong. Java is just checking the equality refrences at this point (remember- a java String is an object made up of chars and other goodies), and that\'s not what we want to do. We want to do is check the _values_ that are stored in the String(s).

So that\'s why we have the String.equals(String) method. Try this out:
if (someString.equals("Yes")) {
     ....
}

Ah- much better. But there is still one more problem. What if for some reason someString is null? Well, we would get a null pointer exception thrown, and probably see a stack trace show up somewhere. A much safer way would be to do it like this:
if ("Yes".equals(someString)) {
     ....
}

And this way, we will never get a null pointer exception.
All things copyright © 2001, 2002 August Mueller

gmdc:
flying meat
contact
resume
photos
images
free font
cocoa bits
java bits
unix bits
osx bits
cvsdist
my words
mcommand
ja
links
my rss feed
book list
who\'s linken\'
login
wishlist
theories

people
andy
byron
jeff
jeremy
joe
kory
lynn
mary
murphy
ryan d

when bored
slashdot
maccentral
y! most viewed
cars
there gus
explodingdog
the onion
dotw
tonypierce
prior art
chimera

resources
Cafe au Lait
Cafe con Leche
design patterns
anitpatterns
java r.o.t.d
c.l.c
c.l.j
c.s.m.p.h
c.s.m.p.c



'''