Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Test processing time (loop vs. contains)
//'main' method must be in a class 'Rextester'. //Compiler version 1.8.0_111 import java.util.*; import java.lang.*; class Rextester { public static void main(String args[]) { List<String> count = new ArrayList<>(); for(int i = 1; i <= 1000000; i++) { count.add(String.valueOf(i)); } long startTime = System.currentTimeMillis(); System.out.println(count.contains("50")); long endTime = System.currentTimeMillis(); System.out.println("contain " + (endTime - startTime)); startTime = System.currentTimeMillis(); for(int i = 0;i < count.size();i++) { if(count.get(i).equals("50")) { System.out.println("true"); break; } } endTime = System.currentTimeMillis(); System.out.println("loop " + (endTime - startTime)); } }
run
|
edit
|
history
|
help
0
Variables&Types
Street light
ArrayOperation
Happy Numbers in Java
Simple imitation for show banners on priorities
Edna Garcia
Bubble Sort
Kochergina_2
SalesmenEarnings
http://stackoverflow.com/questions/23175927/how-to-clone-object-defined-by-interface