我必须迭代一次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)