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:
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started