Mike Simmons wrote:Yes, that would work too. (Yes, parseInt() is not called unless the contains() is false.) I reflexively avoid the contains() method because it seems wasteful to do that and then a get() - I prefer to just do the get and test for null. But then I need another temp variable to hold it in, so I extracted a method, thinking Piet may use it again for other arguments in the code. But, six of one, half dozen of the other - either way works.
Æsthetically, I'd pre-calculate the key into a temporary variable, but that's largely for maintainability. The compiler can optimize out any of the above.
To avoid contains/get, something like this:
Not as elegant, but it avoid the extra lookup.
On the other hand, the trinary operation works when you want test to be
final.