undefined

Measuring list performance

Java Syntax
Level 8 , Lesson 6
Available

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

"Are they interesting?"

"Of course. Very interesting:"

undefined
2
Task
Java Syntax, level 8, lesson 6
Locked
LinkedList and ArrayList
Collections can be implemented in many ways. There is no single implementation that is the most correct. In one approach, some operations are fast, but others are slow. The opposite can be true for another approach. There is no perfect one-size-fits-all solution. We won't torture you by making you choose. Let's just immediately create two different types of lists: LinkedList and ArrayList.
undefined
5
Task
Java Syntax, level 8, lesson 6
Locked
10 thousand deletions and insertions
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.
undefined
2
Task
Java Syntax, level 8, lesson 6
Locked
Time for 10,000 insertions
Time is our most valuable resource. But we don't have any power over time anywhere, except on the planet of Tralfamadore. That's why there are no programmers on Tralfamadore, while Terra is full of them—because they help other people save time. Let's celebrate automation by measuring how long it takes to perform 10,000 insertions on a LinkedList and an ArrayList.
undefined
2
Task
Java Syntax, level 8, lesson 6
Locked
Time for 10,000 get calls
How much time and effort are you willing to spend to get something good? As long as it takes, we think. After all, you're currently trying to become a programmer. Let's see how long it takes to make 10,000 get calls on a LinkedList and an ArrayList. The getGetTimeInMs method must return its execution time in milliseconds.
undefined
2
Task
Java Syntax, level 8, lesson 6
Locked
Method quartet
In this task, we'll be working with a LinkedList and an ArrayList as follows. We need to implement 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). But you don't need to measure anything.
undefined
10
Task
Java Syntax, level 8, lesson 6
Locked
Longest sequence
If numbers repeat themselves, does that mean that somebody wants it that way? At present, we need repeated numbers to practice completing tasks with lists. Let's create a list of numbers and add 10 numbers from the keyboard. Our task is to display the length of the longest sequence of repeating numbers in a list.
Comments (32)
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION
MCantu Level  8, Texas, United States
8 February 2021
So what is the difference between the following codes in a standard for loop: list.get(i) //I know this holds the current element in the list. list.get(i+1); list.get(i -1) list.get(i) + 1) //I think this one grabs the next element following the current element???? list.get(i) -1) I am a little confused as to what they return. Thanks.
Guanting Liu Level  13, Springfield, United States
9 November 2020
Pro tip : if u are stuck on an simple task and u are confident about your correctness,cut your code and repaste it after resetting the task
ziv fisher Level  9, Petah Tikva, israel
26 September 2020
This a hint for: "Longest sequence":

if (i!=list.size()-1)
Meaning if the loop's index is the last one-DO NOT USE (i+1)-as an index. Because there is no more indexes after the last one.
Jeanne Vo Level  22, Olympia, United States
3 July 2020
The task "Time for 10,000 insertions" is a proof for the fact that insertions in LinkedList is way faster than in ArrayList.
FullMet Level  29, Kyiv, Ukraine
8 March 2020
a little tip for the "Longest sequence" for everyone who need it. 1. ArrayList<Integer> list, isn`t a primitive data type and his data(Integers inside it) too. It`s complicated. So you can`t compare its data like this

if (list.get(i) == list.get(i + 1)) {...}
You can compare its data only that way

if (list.get(i).equals(list.get(i + 1))) {...}
2.To find the longest sequence, try to use ints, which I called

int maxSequence = 1;
int currentSequence = 1;
and save your calculations with sequences to them. I hope I can help you a little , guys, good luck , everyone)
Goran Level  28, Belgrade, Serbia
4 March 2020
You can solve it also with == instead of equals :)
Thomas Sixberry Level  16, Rochester Hills, United States
28 January 2020
When it comes to ArrayLists.. I still have no idea what to do. I think Level 7 Syntax messed with my head too bad. And while viewing other people's levels and the dates of their comments, it seems they too have become hung up somewhere and they quit this program.
jawad Level  10, Lahore, Pakistan
6 January 2020
i have a confusion what does list.size()-1 do?
Nyerges Ferenc Level  23, Bükkábrány, Hungary
31 December 2019
Last one is excellent, also fallen into the trap of == :-)
AP Level  15, Bodmin, United Kingdom
30 December 2019
nice one!! took 2 attempts just because of == operator and Integer cache issue. used one for loop and 2 if statements. I must say it is a nice exercise to tell us the issue with Integer class cache and == operator. Now I will always remember to use .equals method whenever I use Integer class and not the primitive type.