I was wondering,
In Java, in a switch
statement what is the access time needed to reach the block of code identified by the input switch
value?
It is a complete sequential search?
it is a direct access? And if so, how it's implemented?
I was wondering,
In Java, in a switch
statement what is the access time needed to reach the block of code identified by the input switch
value?
It is a complete sequential search?
it is a direct access? And if so, how it's implemented?
"Deciding whether to use if-then-else statements or a switch statement is based on readability and the expression that the statement is testing. An if-then-else statement can test expressions based on ranges of values or conditions, whereas a switch statement tests expressions based only on a single integer, enumerated value, or String object." - JavaDocs http://docs.oracle.com/javase/tutorial/java/nutsandbolts/switch.html
"It uses the lookupswitch JVM instruction, which is essentially a table lookup" - How does Java's switch work under the hood?
Worrying about 'access time is micro optimization and premature optimization, which are evil. Rather worry about readabililty and maintainability of the code in question.' - What is the relative performance difference of if/else versus switch statement in Java?