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
Please help ASAP, will mark brainliest!
sp2606 [1]

Answer:

Stick to concrete nouns

Explanation:

The best technique to improve the web search result is that search with the help of keywords. These keywords help in searching the required results from search engines.

The keywords are actually nouns. Noun is name of object, place or person. So by using nouns we can search out required results.

For example

If we want to search about some persons bibliography, we use his name in our search. His name is an example of noun.

3 0
3 years ago
3 features of digital computer​
jolli1 [7]

Answer:

A typical digital computer system has four basic functional elements: (1) input-output equipment, (2) main memory, (3) control unit, and (4) arithmetic-logic unit. Any of a number of devices is used to enter data and program instructions into a computer and to gain access to the results of the processing operation.

Explanation:

6 0
2 years ago
Mad libs are activities that have a person provide various words, which are then used to complete a short story in unexpected(an
Vsevolod [243]

did you just put random a*s word together and expect us to know the ¨answer¨

5 0
3 years ago
Explain why a single 500 kg block of granite weathers much more slowly than 100 chunks of granite weighing 5 kg each.
Bad White [126]
Weathering occurs on the surface of rocks, and lots of small rocks have a much greater surface area than one big rock.
3 0
3 years ago
Read 2 more answers
Scrieți un program care citește un număr natural n și determină suma cifrelor divizibile cu 3 ale lui n.
Vika [28.1K]
Sorry I don't understand your question
5 0
3 years ago
Other questions:
  • A size of a jumbo candy bar with rectangular shape is l x w x h. Due to rising costs of cocoa, the volume of the candy bar is to
    9·1 answer
  • You can add envelopes to existing documents. <br> a. True <br> b. False
    10·1 answer
  • Describe the benefits and drawback of using virtualisation on a single machine and also in a cluster environment
    10·1 answer
  • Do people answer questions more on this site or be on social more ??? no right or wrong answer your opinion
    6·1 answer
  • With a presentation open, you can hover your mouse pointer over a design theme on the Design tab, and PowerPoint will display th
    14·1 answer
  • Why are I/O (input/output operations) important in database environment?
    8·1 answer
  • What do you hope will be in/added GTA 6?
    13·1 answer
  • 30 points Fill in the blanks,<br> Plz leave a explanation
    5·2 answers
  • What are some examples and non-examples of digital security?
    6·1 answer
  • 10.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!