Question: In this assignment, we will compare the performance of three similar data structures in Java : arrays, ArrayList and LinkedList. For these three data structures,

In this assignment, we will compare the performance of three similar data structures in Java: arrays, ArrayList and LinkedList. For these three data structures, we will measure the time it takes to create and initialize an object with one million Integer values. To measure execution time of a code block, you can call the method System.nanoTime() before and after the code block and the difference between the returned values is the time taken to complete the code block. The following code snippet shows how to measure the execution time of a for loop:

In this assignment, we will compare the performance of three similar data

Create a class with name CompareTimes. For each data structure, create a method that returns the time it takes to create an object from that data structure and initializing it with the numbers from 0 to 99999. Then, display the results similar to the below sample output:

Array: 54952999

ArrayList: 82641648

LinkedList: 127078910

long start Time = System.nanoTime(); for (int iter= 0; iter 10000; iter++) { long endTime = System. nanoTime(); long exeTime = endTime- startTime ; System.out.println( Execution Time:" + exeTime)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!