>Just to make sure that it is confusing, you can make strings resolve to the
same
>object by interning them...
>so you could do this:
>
>String s = Request.Form("myFormElement");
>s.intern();
>if (s=="myString") {
> // Do something
>}
>
This is an aside, but sort of interesting: intern()ing strings and then
using == to compare them is not actually faster in a lot of cases than
simply comparing them with .equals().
Why?
When you intern() the string, the hashing function is run on it, which often
looks at more than the first few characters of the string to compute the
result of the function. In the JDK, as I remember, if the string is up to
16 characters long it looks at every character.
In contrast, most strings can be distinguished from one another by simply
examining the first few characters of both. If the .equals() method is
written at all sanely (and in the JDK at least it is), then it should return
immediately after it finds a difference between the two strings.
Of course, your mileage will vary. If you are comparing a lot of strings
that are both long and relatively close to one another in their first
characters, you might see better performance with intern() and == than with
.equals(). With most processing, though, .equals() is usually the route to
go.
--Mike
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html