CodeGym /Courses /New Java Syntax /Measuring list performance

Measuring list performance

New Java Syntax
Level 14 , Lesson 5
Available

"Finally! I missed you. Where have you been? Here are some tasks for you."

"Are they interesting?"

"Of course. Very interesting:"

14
Task
New Java Syntax, level 14, lesson 5
Locked
LinkedList and ArrayList
You need to create two lists: a LinkedList and an ArrayList.
14
Task
New Java Syntax, level 14, lesson 5
Locked
10 thousand deletions and insertions
Using an ArrayList and LinkedList, perform 10,000 insertions, deletions, and get and set calls.
14
Task
New Java Syntax, level 14, lesson 5
Locked
Measure how long it takes to perform 10,000 insertions on each list.
Measure how long it takes to perform 10,000 insertions on each list. The getInsertTimeInMs method must return its execution time in milliseconds.
14
Task
New Java Syntax, level 14, lesson 5
Locked
Measure how long it takes to perform 10,000 get and set calls on each list
Measure how long it takes to perform 10,000 get and set calls on each list. The getGetTimeInMs method must return its execution time in milliseconds.
14
Task
New Java Syntax, level 14, lesson 5
Locked
Method quartet
Implement the 4 methods. Each of them should return the list that is best suited for performing the corresponding operations (i.e. the list that can most quickly perform a large number of operations). You don't need to measure anything.
14
Task
New Java Syntax, level 14, lesson 5
Locked
Longest sequence
1. Create a list of numbers. 2. Use the keyboard to add 10 numbers to the list. 3. Display the length of the longest sequence of repeating numbers in the list. Example for the list 2, 4, 4, 4, 8, 8, 9, 12, 12, 14: 3 The value is 3, because the longest sequence of repeating numbers is three fours.
Comments (53)
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION
larsintech Level 15, Switzerland Expert
3 February 2025
The longest sequence task took me 1 h to solve and a little just a tiny bit of ChatGPT
Krig Raseri Level 38, Dallas, United States
9 September 2022
I interpreted this as the longest sequence of numbers, as in 4 was the most prevalent. It was not until I failed the check that it said UNBROKEN. I mean that's kinda what sequence means I suppose, just glossed over it. I even did a cool thing that used the arraylist and a hashmap, where the key was the number and the value was Collections.frequency so it equaled the amount of times said number occurred. Then slap in Collections.max etc etc. I was so stoked for this too. but I played myself.
Krig Raseri Level 38, Dallas, United States
9 September 2022
Let this be a memorial. RIP Krig's neat idea Sep. 2022.
Anonymous #11003450 Level 20, Canada
10 July 2022
for the las one, I used a Set, 2 different arraylist. I was able to find what was required for the longest sequence, but it did not pass the check. Does the code have to match what the creators put in? There are different ways of getting the same result.
Pumbas Level 19, Germany
19 April 2022
Last one was a great one, but i think you should have added the option to reorganize the ArrayList, because if you enter a random list, it will not give a correct result since he will check the next one and can be that is allways different, even is the Array as equal numbers... So first i added code to organize the ArrayList and then checked for equals. Still nice tho :)
cnsacramento Level 10, El Dorado Hills, España
11 March 2022
I really like so much the last practice. It's a good to remember that List doesn't work with primitive types so you have to remember how to compare two non-primitive types
Jonaskinny Level 25, Redondo Beach, United States
17 February 2022
good test of our knowledge re comparing int vs Integer and auto-boxing ... 1==1 -> true 127==127 -> true 128==128 -> false (because we are storing Integer instead of int, so when we get passed byte max 127, we go to true reference comparisons, where @Object12345:value128==@Object54321:value128 -> false but @Object12345:value128.equals(@Object54321:value128) -> true
Le Phan Level 14, Véry, France
5 February 2022
Here is a short, simple but good surfed post for various methods using to measure the eslaped time.Baeldung.com/java-measure-elapsed-time
Harvey Roberts Level 9, Helsinki, Finland
21 October 2021
In the 10000 insertions and deletions you ask this: 5. The get10000(List list) method should call get 10,000 times on the list. In your solution you have the number 5000. Where does that number come from??
John Squirrels Level 41, San Francisco, Poland
21 October 2021
5000 is just an example. You do not have to use this index, you can just use index i (for example, list.get(i);).
CaseyMacy Level 22, Denver, United States
1 April 2022
This is good to remember if you ever need to add items to the middle of a list; just specify the index where you want to insert items (index, item)
Franco Polizzi Level 11, Werther, Germany
25 August 2022
Strange.. simple list.clear(); is fine for the remove10000 method.
Maryam Roudbari Level 41
17 September 2021
can anyone give some hint about int x = list.size() / 2 in Time for 10,000 get calls?
Jonaskinny Level 25, Redondo Beach, United States
17 February 2022
red herring ...
sgubow Level 10, Forest Grove, United States
4 May 2021
Is it just me or does it feel like they don't teach us most of how to solve these problems then I have to scratch my head at each one for 10 minutes without typing...
Le Phan Level 14, Véry, France
5 February 2022
Well, for saying things properly, we are learning from practice. In reality, there are cases whereas we have to solve unfamiliar problems. How you intend to solve them without much knowledge or even preparation? Thinking twice, trial-and-fail, asking for help, doing research for similar cases, etc., right? CodeGym studying process is the same like that. You are learning from reality, not from a textbook, man!
Jonaskinny Level 25, Redondo Beach, United States
18 February 2022
I think they are making sure you have seen what you need to know, gotten through the exercises (muscle memory), gotten a little lesson afterwards (once you did some self study to understand the exercise which is what happens at work all the time) to make sure you know what aspects to study should you wish to.