Most of the strings we are talking about are dynamic (or at least run-time
configurable), so we would have to do string.intern() to be able to use ==
and I don't think that you'd want that internal list of strings growing like
that.  Besides, when you have a new string and do an intern(), it looks up
the common string in a hashtable using hashcode to return the string on
which you can do == on.

Michael

-----Original Message-----
From: Adam Heath [mailto:[EMAIL PROTECTED]]
Sent: Thursday, February 07, 2002 1:17 PM
To: marc fleury
Cc: Jboss-Development@Lists. Sourceforge. Net
Subject: Re: [JBoss-dev] so how fast is string comparison


On Thu, 7 Feb 2002, marc fleury wrote:

> when we do
>
> if (string.equals("this"))
>
> else if (string.equals("that"))
>
> how much slower is it than
>
> switch (stringAsInt)
> case THIS:
>
> case THAT:

If strings are final, then you can use ==, instead of the much slower
.equals().

A switch stmt is really nothing more than a series of if/elseif blocks.  So,
making all strings static/final, and using ==, should make for a win,
without
making the code hard to read by using abstract ints.



_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to