On Apr 29, 10:44 am, Kent Yip <yes...@gmail.com> wrote:
> a switch statement is made for nested if statements.

Actually it's not.  Both Java and Dalvik have "sparse" and "packed"
switch instructions at the bytecode level.  You can read about them in
the Dalvik bytecode documentation in dalvik/docs/dalvik-bytecode.html
(packed-switch/sparse-switch, corresponding to tableswitch/
lookupswitch in Java).

> switch statement is greate if you have a bunch of selections, to make a
> switch statement perform better you have to look at what user will likely
> selection the most, and implement that case on the top most case in the
> switch. Accessing that case will be faster than accessing cases at lower end
> of the switch statement.

Not really.  For a "packed" switch, which is essentially a goto table,
everything is the same speed.  For a "sparse" switch, the VM can
either do a linear search or a binary search through the table,
because the entries are sorted by the "case" value.  Note also that
the sorting makes rearranging entries in the source code meaningless.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to