Respuesta :
After measuring the computation time and analyzing the code, it is concluded the processing time is the same because both list1 and list2 contain the same number of elements.
Java code
import java.util.ArrayList;
import java.util.Iterator;
public class Main {
public static void main(String[] args) {
- //Create myarraylist and mylinkedlist, both as arraylist objects
ArrayList < Double > myarraylist = new ArrayList < > ();
ArrayList < Double > mylinkedlist = new ArrayList < > ();
- //Create list1 and list2 as myarraylist and mylinkedlist objects respectively
ArrayList list1 = new ArrayList(myarraylist);
ArrayList list2 = new ArrayList(mylinkedlist);
- //Adding a million double numbers to the lists
- double a = 0;
for (int i = 0; i < 1000000; i++) {
a += 1;
list1.add(a);
}
a = 0;
for (int i = 0; i < 1000000; i++) {
a += 1;
list2.add(a);
}
- //Display the size of the lists
System.out.println("List1: " + list1.size() + " items");
System.out.println("List2: " + list2.size() + " items");
- // Measuring the time before removing the elements from list1
long miliSec1 = System.currentTimeMillis();
- //Removing the first element of the list a million times until the list is empty
while (list1.size() > 0) {
list1.remove(0);
}
- // Measuring the time after removing the elements from list1
long miliSec2 = System.currentTimeMillis();
- // display the results of the calculation time
System.out.println("Time taken to remove items from list1: " +
(miliSec2 - miliSec1) + " miliseconds");
- // Doing the same with list2
miliSec1 = System.currentTimeMillis();
while (list2.size() > 0) {
list2.remove(0);
}
miliSec2 = System.currentTimeMillis();
System.out.println("Time taken to remove items from list2: " +
(miliSec2 - miliSec1) + " miliseconds");
}
}
To learn more about analyzing java codes see: https://brainly.com/question/9087023
#SPJ4
