Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a java program that a) Creates three arrays (of the class created in part

ID: 3663500 • Letter: W

Question

Write a java program that
a) Creates three arrays (of the class created in part 2) with max_size of 100, 10000 and
1000000 elements
b) Populates the three arrays with random integers in the range 0-max_size-1 (by using
the insert method in a loop).
c) Deletes any one element and times the operation
d) Finds one element and times the operation (search for the number max_size)
e) Inserts one element and times the operation (do this after delete or your element won’t
fit in the array)
f) Provide the source code and the running times for each operation in milliseconds

Explanation / Answer

a. import java.util.Arrays;
import org.apache.commons.lang.ArrayUtils;

public class Program {

b. import java.util.Arrays;
import org.apache.commons.lang.ArrayUtils;

public class Random_Integers{

c. import java.util.Arrays;

import org.apache.commons.lang.ArrayUtils;

public class RemoveObjectFromArray{


  public static void main(String args[]) {
  
  int[] test = new int[] { 101, 102, 103, 104, 105};
  
  System.out.println("Original Array : size : " + test.length );
  System.out.println("Contents : " + Arrays.toString(test));

test = ArrayUtils.remove(test, 2);

  System.out.println("Size of array after removing an element : " + test.length);
  System.out.println("Content of Array after removing an object : "

                           + Arrays.toString(test));

}

}

d. import java.util.Arrays;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class SearchTest {

  public static void main(String args[]) {

  List<Integer> array = Arrays.asList(1, 3, 5, 2, 4);
  if (array.contains(3)) {
  System.out.println("Element found inside Java array using" +

                                 "ArrayList contains() method");
  };

  Set<Integer> arraySet = new HashSet<Integer>(array);

  if (arraySet.contains(3)) {
  System.out.println("Element found on Java array using" +

                                 "HashSet contains method");
  };

  String[] cities = new String[]{"Washington", "London", "Paris", "NewYork"};
  
Arrays.sort(cities);

if(Arrays.binarySearch(cities, "Paris") >=0 ){
  System.out.println("Element found on sorted String Java" +

                                  "array using binary search");
  }

  String input = "London";
  for(String city: cities){
  if(city.equals(input)){
System.out.println("Found elements in Java array using for loop");
  }
  }

  }
}

e.

f.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote