public static void get10000(List list) {
if (list.isEmpty()) return;
int x = list.size() / 2;
for (int i = 0; i < 10000; i++) {
list.get(x);
}
}
Can some one explain what is purpose of int x = list.size()/2; ?
If i understand it correctly it will all ways get same value from list or I am wrong ?Need clarification for part of code, not solution
Under discussion
Comments (3)
- Popular
- New
- Old
You must be signed in to leave a comment
Adarsh
29 June 2020, 12:07
It simply getting the value present at index 5000.
0
Shuy
4 March 2020, 11:43
In my opinion it would. X wont change at all during the For Loop, so all list.get(x) will always return the same value. The int x = list.size() / 2 statement will get you to the middle of the list. I just dont get the point of the for loop.
0
Goran
5 March 2020, 22:11
It is just part of method. I copied complete method. Actually second for loop is doing all job, because request is to get 10 000 get() requests.
0