小编Gab*_*abu的帖子

迭代for循环的哪种方式更好?

我必须迭代一次for-loop,但我想知道哪种方式更好.

1:

import java.util.ArrayList;

public class FindTime {
    public static void main(String[] args) {
        ArrayList tmpList = new ArrayList();
        tmpList.add("me");  tmpList.add("you ");
        tmpList.add("I");   tmpList.add("Us");
        tmpList.add("me");  tmpList.add("you ");
        tmpList.add("I");   tmpList.add("Us");
        tmpList.add("me");  tmpList.add("you ");
        tmpList.add("I");   tmpList.add("Us");
        tmpList.add("me");  tmpList.add("you ");
        tmpList.add("I");   tmpList.add("Us");
        tmpList.add("me");  tmpList.add("you ");
        tmpList.add("I");   tmpList.add("Us");
        tmpList.add("me");  tmpList.add("you ");
        tmpList.add("I");   tmpList.add("Us");

        long startTime = System.nanoTime();
        for (int i = 0,size=tmpList.size(); i < size; i++) {
            System.out.println(tmpList.get(i).toString());
        }
        long endTime = System.nanoTime();

        System.out.println("Time Duration ::->" + (endTime - startTime));
    }
} …
Run Code Online (Sandbox Code Playgroud)

java for-loop arraylist

4
推荐指数
1
解决办法
158
查看次数

标签 统计

arraylist ×1

for-loop ×1

java ×1