The ability to repeat monotonous actions without whining or goofing off is what makes computers glorious — and it's also what stops programmers from simply keeling over dead! Without a way to automate repetitive actions, the conditions for this task would sound like a prison sentence. As things stand, everything will be just fine: using an ArrayList and LinkedList, perform 10,000 insertions, deletions, and get and set calls.
10 thousand deletions and insertions
- 5
Locked
Comments (15)
- Popular
- New
- Old
You must be signed in to leave a comment
Thi Java Developer
1 March, 19:18
Using while loop + iterator().hasNext() method for last requirement is also a way.
0
Xavi MartinExpert
3 November 2022, 07:13
why did we pass 5000 in the loop? I don't understain
0
Andrew Evans
11 February 2022, 17:37
Neat trick for remove is to go backwards. Think about it.
0
carlos oliveira
9 November 2021, 03:35
All BS... the secret is just read how the "remove method" works in Collections. everey time you remove an object from a list/arrayList it's decreases the list indice by 1. so, if you are trying to remove "n" objects in a loop make sure to decrease the inner indice by 1 and increase the outer indice by 1.
0
harshshah
20 June 2021, 06:52
It is not neccessary to use 5000.
You can just use Your initialized variable in for loop as argument.
Eg; for(int i=0; i<1000; i++){
list.get(i); }
for set: list.set(i, list);
list is an object name, used as input argument in method for given task.
0
Anonymous #10690611 Java Developer
10 February 2021, 18:41
In get10000, the loop is going to run 10000 times. Why do we use list.get(5000)?
+1
remote87
10 January 2021, 15:15
Is this right: to end it with just one method or we should find another way?
0
Rishabh Joshi
15 December 2020, 12:42
why did we pass 5000 in get and set operations in the loop
0
Mihai Bone
22 December 2020, 23:27
When you try to remove with a for loop .... it will be stuck at only 5000
I did put in all the methods System.out.println("Method name :" + list.size()); to check were is the problem.......... you can try it (I will not give the answer, it will lose the purpose of the exercise)
0
Anonymous #10690611 Java Developer
10 February 2021, 18:39
Why do we need to use 5000 again in list.get(5000)? Why does it need to be half of 10000?
0
Nutty Coder
30 October 2020, 20:41
There is also a simple method for the last requirement in the method list here.
https://docs.oracle.com/javase/8/docs/api/java/util/ArrayList.html
0
Muhammad Vahhaaj
3 July 2019, 13:29
use while loop and isEmpty method for last requirement
+1
Thi Java Developer
1 March, 19:18
Thank you! Using while loop + iterator().hasNext() is also a way.
0