1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
scoundrel [369]
3 years ago
5

Write a class that can make comparisons between the efficiency of the common methods from the List interface in the ArrayList an

d LinkedList classes such as add, get, and remove. Use the polymorphic-variable technique described above to write the class so that it only knows it is performing its tests on objects of the interface type List rather than on the concrete types ArrayList and LinkedList. Use large lists of objects for the tests, to make the results significant. You can use the currentTimeMillis method of theSystem class for getting hold of the start and finish time of your test methods.

Computers and Technology
1 answer:
Alika [10]3 years ago
6 0

Answer:

Check the explanation

Explanation:

CODE TO COPY:

File: ArrayListVsLinkedlIst.java

// ArrayListVsLinkedlIst class implementation

import java.util.*;

public class ArrayListVsLinkedlIst

{

  public static void main(String[] args)

  {

      // create a constant for the size of each list

      final int SIZE = 300000;

      // create the required objects

      List<Integer> aList = new ArrayList<Integer>();

      List<Integer> lList = new LinkedList<Integer>();

      // declare the required variables

      long start, end;

      int i;

      // comparison between the efficiency of the add() method

      // from the ArrayList and LinkedList classes

      System.out.println("Time in milliseconds to add " + SIZE

              + " numbers to each list ...");

      start = System.currentTimeMillis();

      for (i = 0; i < SIZE; i++)

      {

          aList.add(i);

      }

      end = System.currentTimeMillis();

      System.out.println("ArrayList: " + (end - start) + " ms");

      start = System.currentTimeMillis();

      for (i = 0; i < SIZE; i++)

      {

          lList.add(i);

      }

      end = System.currentTimeMillis();

      System.out.println("LinkedList: " + (end - start) + " ms");

      // comparison between the efficiency of the get() method

      // from the ArrayList and LinkedList classes

      System.out.println("\nTime in milliseconds to get " + SIZE

              + " numbers from each list ...");

      start = System.currentTimeMillis();

      for (i = 0; i < SIZE; i++)

      {

          aList.get(i);

      }

      end = System.currentTimeMillis();

      System.out.println("ArrayList: " + (end - start) + " ms");

      start = System.currentTimeMillis();

      for (i = 0; i < SIZE; i++)

      {

          lList.get(i);

      }

      end = System.currentTimeMillis();

      System.out.println("LinkedList: " + (end - start) + " ms");

      // comparison between the efficiency of the remove() method

      // from the ArrayList and LinkedList classes

      System.out.println("\nTime in milliseconds to remove " + SIZE

              + " numbers from each list ...");

      start = System.currentTimeMillis();

      for (i = 0; i < SIZE; i++)

      {

          aList.remove(0);

      }

      end = System.currentTimeMillis();

      System.out.println("ArrayList: " + (end - start) + " ms");

      start = System.currentTimeMillis();

      for (i = 0; i < SIZE; i++)

      {

          lList.remove(0);          

      }

      end = System.currentTimeMillis();

      System.out.println("LinkedList: " + (end - start) + " ms");

  }

} // end of ArrayListVsLinkedlIst class

The screenshot and output images can be seen below.

You might be interested in
what tool can a student use to make sure his or her work paper does not take credit for someone else's work ?
AlekseyPX

You can use a plagiarism checker.

8 0
3 years ago
If you wanted to round $3.99 located in Cell B3 to the nearest dollar, what is the correct Microsoft excel formula?
natali 33 [55]
<span>The formula is B.=ROUND(B3,0)

So, the format is = ROUND (cell #, # of decimal places) 

well if # of decimal places is 0, it just rounds to the nearest integer.

Happy studying ^-^


</span><span>
</span>
6 0
3 years ago
Read 2 more answers
How to use 2 tabs at once on my Lenovo yoga book?​
svp [43]
To turn on Multi-window: Method 1: Swipe up from the bottom of Home screen to show Bottom switch, touch Multi-wins. Method 2: Tap Settings on Home screen, tap Multi-window, check Multi-window on the right.
3 0
3 years ago
Word can store a maximum of how many documents in its Recent Documents area? five ten fifteen twenty
djyliett [7]
The answer is twenty.
5 0
3 years ago
So, I have an Cru__ on this boy in school and his name is Bray but Yeah.............Can someone help me
tester [92]

Explanation:

Okay so, am not a great person at that but my best advice would be. to be yourself. you can always be honest and talk to him privately that you have a crush on him. Dont be afraid and if he doesn't go to well dont feel bad, at least you had the guts to tell him. other girls would be scared.

4 0
3 years ago
Read 2 more answers
Other questions:
  • Write a complete C++ program that do following. Read a positive integer from the user with proper prompt. Assume that this user
    9·1 answer
  • The ____ button resets slide placeholders to their default position, size, and text formatting.
    11·1 answer
  • Choose a developing country and give 3 reasons why it is a developing country ​
    15·1 answer
  • Harmful programs used to disrupt computer operation, gather sensitive information, or gain unauthorized access to computer syste
    7·1 answer
  • Allows a user to control the<br>volume of the computer​
    8·1 answer
  • One tool under What-If-Analysis is Scenarios. Which best describes the purpose of setting up and using scenarios
    5·1 answer
  • What are the benefits of building redundancy into a network?
    12·1 answer
  • WILL GIVE BRAINLIEST ANSWER!!!<br><br> How do you manage your screen time?
    8·2 answers
  • 1. You are given a database to create, however, you realize that in the instructions you are told to create relationships betwee
    5·1 answer
  • How many pages is 1500 words double spaced 12 font?.
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!