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 case-insensitive compare.
While I am at it, this code all represents appropriate use of type String.
But note that all String variables in Java are const. So if you start
modifying the string, it gets very inefficient. In those circumstances you
should be using StringBuffer.
JT
<< 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"))"? >>