Java for loop performance question

前端 未结 13 1203
长发绾君心
长发绾君心 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:40

    Java compiler would have optimized it so, but didn't do so by seeing the funny condition. If you wrote it like this there would be no issue.

    for (int i = myList.size(); i < 1000000; i--) {
        System.out.println("Hello");
    }
    

提交回复
热议问题