Question
package arraylists; import java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; import java.util.Random; public class arraylists { public final static int MAX = 1000; static Random rand =
package arraylists;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
import java.util.Random;
public class arraylists {
public final static int MAX = 1000;
static Random rand = new Random();
static int rand_int1 = rand.nextInt(1000);
static int rand_int2 = rand.nextInt(1000);
public static void array(int [] a1 ) {
int [] arry = new int[MAX];
for(int i = 0; i < MAX; i++) {
a1[i] = rand_int1;
}
}
public static void arrayList(int [] a2) {
ArrayList
for(int i = 0; i < MAX; i++) {
num.add(i);
}
}
public static void main(String args[]) {
//int [] arry = new int[MAX];
int num;
System.out.println("Enter the number of iterations: ");
Scanner input = new Scanner(System.in);
num = input.nextInt();
I am trying to write functions that generate an array of size MAX and assign them random values using a function for arrays and arraylists. I want to compare the time it takes for it to be added. can you help me with this
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