public static ArrayList doArrayListSearchGreatestint numItem

   public static ArrayList<Integer> doArrayListSearchGreatest(int numItems) {

       System.out.print(\"doArrayListSearchGreatest: \");

       ArrayList<Integer> list = new ArrayList<>();

       // TODO Write code that adds integers 0 through (numitems - 1)

       // to list.

       long startTime = getTimestamp();

       // TODO Write code that gets the element at the last index from list.

       long endTime = getTimestamp();

       long totalTime = endTime - startTime;

       System.out.println(totalTime);

      

       return list;

   }

Solution

Code that appends integers 0 through (numitems - 1) to the list. I have added a loop for adding values to the list

for(int i=0; i<numItems-1; i++){

       list.add(0);

   }

Then the entire program becomes

public static ArrayList<Integer> doArrayListAdd(int numItems) {

   System.out.print(\"doArrayListAdd: \");

   ArrayList<Integer> list = new ArrayList<>();

      for(int i=0; i<numItems-1; i++){

       list.add(0);

   long startTime = getTimestamp();

   }

   // TODO Write code that gets the element at the last index from list.

   int lastNumber = list.get(list.size()-1);

   long endTime = getTimestamp();

   long totalTime = endTime - startTime;

   System.out.println(totalTime);

   return list;

   }

 public static ArrayList<Integer> doArrayListSearchGreatest(int numItems) { System.out.print(\
 public static ArrayList<Integer> doArrayListSearchGreatest(int numItems) { System.out.print(\

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site