The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

Quicker equality check?

I have an if statement and the entry condition requires the checking equality of a character against several other characters. Is it possible to put these several characters into a list to shorten the code? At the moment I have

Re: Quicker equality check?

A couple of caveats: shorter code != quicker execution as your question presupposes. Secondly there is quicker and quicker: the hearts of people at the base of a mountain beat more quickly than those at the top (and their lives are correspondingly shortened). It's a general relativistic effect and it is simply *not* worth worrying about (unless your clocks are launched into space as part of a military grade GPS system in which case the clock speed in a gravitational field matters). The time savings you are chasing are, similarly, more theoretical than real.

There is a String method that will test whether a character is present in a String and that could be used here. The resulting code would be more readable and that matters more than speed.