Java for loop performance question

前端 未结 13 1193
长发绾君心
长发绾君心 2020-12-15 05:17

considering this example:

public static void main(final String[] args) {
    final List myList = Arrays.asList(\"A\", \"B\", \"C\", \"D\");
            


        
13条回答
  •  不思量自难忘°
    2020-12-15 05:53

    With the last example you will not need to resolve the current size of the array so it will be slightly faster then the first example.

    Just remember that this is only useful if you don't change the number of values in your array.

    In Android it is recommended to use the latest example in there example, Designing for Performance. http://developer.android.com/guide/practices/design/performance.html#foreach

提交回复
热议问题