Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Experts Guide To Database 2

Authors: Bruce L. Larson

1st Edition

0070232679, 978-0070232679

More Books

Students also viewed these Databases questions