Originally posted by Tom Scott:
what if the assumption about these chars turned out to be wrong due to bad data or changing system behaviour
You have to determine whether you really do need to compare all characters. If you do, nothing will beat String.equals(). If you don't, a custom-written equality test or a regex might theoretically do a bit better - if that little bit of performance really matters to you.
If you use assertions, you might consider an assertion that documents and checks your assumptions about the format. This would alert you to problems, during development, but could be turned off for production code.
[ October 18, 2007: Message edited by: Peter Chase ]