10 thousand deletions and insertions

  • 5
  • Locked
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.
You can't complete this task, because you're not signed in.
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.
Xavi Martin
Level 22
Expert
3 November 2022, 07:13
why did we pass 5000 in the loop? I don't understain
Andrew Evans
Level 17 , San Jose, Canada
11 February 2022, 17:37
Neat trick for remove is to go backwards. Think about it.
carlos oliveira
Level 10 , Seattle, United States
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.
harshshah
Level 9 , Gandhinagar, India
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.
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)?
remote87
Level 18 , Sofia, Bulgaria
10 January 2021, 15:15
Is this right: to end it with just one method or we should find another way?
Rishabh Joshi
Level 9 , Indore, India
15 December 2020, 12:42
why did we pass 5000 in get and set operations in the loop
Mihai Bone
Level 8 , Bucharest, Romania
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)
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?
Nutty Coder
Level 8 , United States
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
Muhammad Vahhaaj
Level 19 , Rawalpindi, Pakistan
3 July 2019, 13:29
use while loop and isEmpty method for last requirement
Thi Java Developer
1 March, 19:18
Thank you! Using while loop + iterator().hasNext() is also a way.