Question: In Java. I need help writing this small program, the intention here is to time the filling of an array and an arraylist and compare

In Java. I need help writing this small program, the intention here is to time the filling of an array and an arraylist and compare how much time it takes. The method fill should fill an array with 10,000,000 random values. It should then time how long it takes using the system timer. It should do the same for an arraylist with its own seperate time. The times should castes to string and then passed to a constructor. The constructor uses the DecimalFormat class to output the times in the following format "0.00". The output of the program should be the following:

Fill race, N = 10,000,000 array fill: ?? seconds arrayList fill: ?? seconds

I will now post the code I have so far:

import java.util.Random; import java.text.DecimalFormat; public class ArrayTest { int N=10000000; int [] theArray= new int[N]; Random rand = new Random(); public void fill(){ long startTimeArray1=System.currentTimeMillis(); for(int i=0;icurrentTimeMillis(); long fillTimeA1=(endTimeArray1-startTimeArray1)/1000; String fillTimeString=Long.toString(fillTimeA1); System.out.println(fillTimeString); } public static void main(String[] args) { ArrayTest test = new ArrayTest(); test.fill(); } } 

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!