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
In your code editor, there is some code meant to output verses of the song "old macdonald had a farm. " when the code is working
iris [78.8K]

Using the knowledge in computational language in python it is possible to write a code that  meant to output verses of the song "old macdonald had a farm.

<h3>Writting the code:</h3>

def main():

   # Make a list containing animals and sounds.

   #     Element n is the animal and n+1 is its sound.

   animals = ['cow', 'moo', 'chicken', 'cluck', 'dog', 'woof', 'horse', 'whinnie', 'goat', 'blaaah']

   # For each animal/sound pair

   for idx in range(0, len(animals), 2):

       # Call song(), passing the animal/sound pair as parameters.

       song(animals[idx], animals[idx+1])

       print()

# song():

#   animal and sound are arguments

def song(animal, sound):

   # Call firstLast() for first line of song

   firstLast()

   # Call middleThree() for middle three lines, passing animal and sound

   middleThree(animal, sound)

   # Call firstLast() for last line of song

   firstLast()

# firstLast():

def firstLast():

   # Print "Old MacDonald had a farm, Ee-igh, Ee-igh, Oh!"

   print("Old MacDonald had a farm, Ee-igh, Ee-igh, Oh!")

# middleThree():

#   animal and sound are arguments

def middleThree(animal, sound):

   # Print middle three lines of song with passed animal and sound.

   print('And on that farm he had a {0}, Ee-igh, Ee-igh, Oh!'.format(animal))

   print('With a {0}, {0} here and a {0}, {0} there.'.format(sound))

   print('Here a {0}, there a {0}, everywhere a {0}, {0}.'.format(sound))

main()

See more about python at  brainly.com/question/18502436

#SPJ1

5 0
1 year ago
In project management, which step involves the project manager identifying
nasty-shy [4]

Answer: The only help is your lord and savior Jesus Christ Amen YAR

Explanation: The Bible or Church

8 0
2 years ago
The process by which information gets into memory storage is
Kay [80]

Answer:

That is the first step and it is called encoding process.

7 0
3 years ago
2
Crazy boy [7]

If any mistake was made using this type of primitive programming, the entire program of punch cards had to be re punched again. The correct option is A.

<h3>What is punch card?</h3>

A punch card is a card on which data is able to be recorded in the form of punched holes.

Whenever a mistake is done, the punched card is scrapped and made anew one for same programming.

Thus, if any mistake was made using this type of primitive programming. The entire program of punch cards had to be re punched again. The correct option is A.

Learn more about punch card.

brainly.com/question/27476988

#SPJ1

4 0
2 years ago
Why did sugar planters come to Louisiana?​
Fiesta28 [93]

Answer:

Because the soil there was rich and untouched.

Explanation:

5 0
3 years ago
Read 2 more answers
Other questions:
  • "under the control panel, what console contains print management, computer management, and event viewer?"
    11·1 answer
  • What are four different commands in Internet Explorer and identify their keyboard shortcuts
    10·1 answer
  • There is usually a positive side and a negative side to each technology improvement. Select a technology you use every day and c
    5·1 answer
  • How dependent are we on technology? ​
    15·2 answers
  • as the reader, you can figure out the writer's ____ based on his or her word choice and sentence structure a. purpose b. audienc
    11·1 answer
  • The diagnostic test that involves watching a computer monitor with alternating checkerboard patterns while an eeg is performed i
    11·2 answers
  • In a study on software license infringement, those from United States were significantly more permissive than those from the Net
    15·1 answer
  • Write a method that prints on the screen a message stating whether 2 circles touch each other, do not touch each other or inters
    12·1 answer
  • How many people are in Siver, on the game Valorant?
    14·1 answer
  • Describe how you can use JavaScript to simulate the behavior of the placeholder attribute in older browsers
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!