Actually the test that you want is:
if (user.compareTo("admin") == 0) {
...
}
-Original Message-
From: Cliff Rowley [mailto:[EMAIL PROTECTED]]
Sent: Saturday, November 18, 2000 7:35 AM
To: [EMAIL PROTECTED]
Subject: RE: getParameter is NO
Note for newer Java programmers:
For this example, they are equivalent. But String.compareTo() returns an int
and can be used, like the C function memcmp(), to test all of , ==, and .
In addition to String.equals(), do not overlook String.equalsIngoreCase(),
should you need a
if (user == "admin")
{
}
then it doesnt go into this condition, but goes into the ELSE instead!!!
Why is this?
You need to do some basic Java study.
The conditional test above actually asks this:
If
the explicit String type object reference 'user' points to the same
Brett Bergquist wrote:
Actually the test that you want is:
if (user.compareTo("admin") == 0) {
...
}
And how is this any different from using "if (user.equals("admin"))"?
The method 'compareTo(Object o)' is specified in java.lang.Comparable, which
Miles Daffin wrote:
Brett Bergquist wrote:
Actually the test that you want is:
if (user.compareTo("admin") == 0) {
...
}
And how is this any different from using
"if (user.equals("admin"))"?
...
'compareTo(Object o)' returns an int
...
Hi Charles,
A few notes:
1) java.lang.Comparable is new in Java2. It's not there
if you are running w/Java 1.1 (OK with Tomcat 3.x).
2) compareTo(), for Strings does a *lexical* comparison.
Semantically, this code wants to know that the user
is "admin", not that the user is
: getParameter is NOT a string?
Brett Bergquist wrote:
Actually the test that you want is:
if (user.compareTo("admin") == 0) {
...
}
And how is this any different from using "if (user.equals("admin"))"?
--
Kurt Pruenner - Haendel