public class Solution {
public static void main(String[] args) {
System.out.println(getInsertTimeInMs(new ArrayList()));
System.out.println(getInsertTimeInMs(new LinkedList()));
}
public static long getInsertTimeInMs(List list) {
long startTime = System.currentTimeMillis();
insert10000(list);
long timeDifference = System.currentTimeMillis() - startTime;
return timeDifference;
}
public static void insert10000(List list) {
for (int i = 0; i < 10000; i++) {
list.add(0, new Object());
}
}
}
this concept i am not getting properly....
Under discussion
Comments (2)
- Popular
- New
- Old
You must be signed in to leave a comment
KARAN BHOITE
6 August 2019, 00:51
1. in for loop at the time (list.add) why we used 0 instead of i ?
0
Guadalupe Gagnon
12 November 2019, 16:17
that is inserting each element at the beginning of the list (index 0).
0