Hello everyone,
any tips for how to return the time?
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) {
ArrayList arrayList = new ArrayList();
LinkedList linkedList = new LinkedList();// write your code here
insert10000(list);
return ...;// write your code here
}
public static void insert10000(List list) {
for (int i = 0; i < 10000; i++) {
list.add(0, new Object());
}
}
}
Mareike
Level 4
Any tips for how to return the time??
Resolved
Comments (3)
- Popular
- New
- Old
You must be signed in to leave a comment
Okanlawon Oluwatobi Damilare
3 May 2019, 19:46
You can just do this
long StartTime = System.currentTimeMillis();
insert10000(list);
long timeDifference = System.currentTimeMillis() - StartTime;
return timeDifference;
+9
Mareike Frontend Developer
4 May 2019, 07:16
Thanks! Now I get it :)
+1
Guadalupe Gagnon
3 May 2019, 13:57
make a long variable and set it to System.currentTimeMillis()
+4