> 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
String implements.

'compareTo(Object o)' returns an int - It is used when you want to sort a
bunch of Comparable objects
(see the API docs...).

'equals(Object o)' returns a boolean - In this case it returns true if the 2
Strings are the same length and
contain the same characters (same case) in the same order.

'compareTo(Object o)' is used in the Collections framework by various
sorting algorithms.





Reply via email to