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
Nadya [2.5K]
2 years ago
15

Consider the following code segment: ArrayList bulbs = new ArrayList(); bulbs.add(new Light()); bulbs.remove(0); bulbs.add(new L

ight()); Light b = new Light(); bulbs.add(1, b); bulbs.add(new Light()); bulbs.remove(0); bulbs.add(new Light()); bulbs.remove(2); bulbs.add(new Light()); bulbs.add(1, new Light()); After running the code, what is the size of bulbs?
Computers and Technology
2 answers:
mezya [45]2 years ago
6 0

Answer:

4

Explanation:

ArrayList bulbs = new ArrayList();

bulbs.add(new Light()); // bulbs array length equal to 1

bulbs.remove(0); // bulbs array length equal to 0

bulbs.add(new Light()); // bulbs array length equal to 1

Light b = new Light();

bulbs.add(1, b); // bulbs array length equal to 2

bulbs.add(new Light()); // bulbs array length equal to 3

bulbs.remove(0); // bulbs array length equal to 2

bulbs.add(new Light()); // bulbs array length equal to 3

bulbs.remove(2); // bulbs array length equal to 2

bulbs.add(new Light()); // bulbs array length equal to 3

bulbs.add(1, new Light()); // bulbs array length equal to 4

Scrat [10]2 years ago
4 0
To answer this, lets run through the code:

<span>ArrayList bulbs = new ArrayList(); //create a new empty list

bulbs.add(new Light()); //size of bulbs  = 1

bulbs.remove(0); //remove item at index 0. size of bulbs = 0

bulbs.add(new Light()); // size of bulbs = 1

Light b = new Light();
bulbs.add(1, b); // size of bulbs = 2

bulbs.add(new Light()); //size of bulbs = 3

bulbs.remove(0); //remove bulb at index 0. Size of bulbs = 2

bulbs.add(new Light()); size of bulbs = 3

bulbs.remove(2); //remove bulb at index 2. size of bulbs = 2

bulbs.add(new Light()); //size of bulbs = 3

bulbs.add(1, new Light()); //inserted at position 1. size of bulbs = 4

The final answer. Size of bulbs = 4.</span>
You might be interested in
A search engine displays a list of webpage names that contain the search text. what is the term for that list?
Minchanka [31]
<span>A search engine displays a list of webpage names that contain the search text. The term for that list is hit.
Basically, what this term refers to is the number of visits, or a number of downloads that happened on that particular webpage. It is a good tool to measure web traffic, or how much that page is visited.
</span>
6 0
3 years ago
Wich is the correct process for selecting an entire row in a spreadsheet?
umka21 [38]
CTRL - (select sentence) - ALT

4 0
2 years ago
To view the Picture tools tab, a user must first _____.
Amiraneli [1.4K]
Answer: A select the picture
8 0
2 years ago
Read 2 more answers
Diffrence betwwen RAM and ROM​
cestrela7 [59]
Answer : RAM is used to store computer programs and data that CPU needs in real time. ROM have prerecorded data and it is used to boot computer.
5 0
2 years ago
Pls help due tonight<br>Will give brainiest
katrin2010 [14]
HIPPA law is Health Insurance Portability and Accountability Act of 1996. It’s a federal law that helps consumers maintain their insurance coverage.
8 0
3 years ago
Read 2 more answers
Other questions:
  • PLEASE HELP PROGRAMMING WILL GIVE BRAINLIEST
    11·2 answers
  • Într-o curte sunt G găini și O oi. Să se determine numărul de capete și numărul de picioare din curte.
    13·1 answer
  • Amanda needs to create an informative print brochure for her local library’s fundraiser dinner. What critical detail must she ha
    14·2 answers
  • How is the JOptionPaneclass used to display a dialog box that performs a yes/noconfirmation?
    10·1 answer
  • Complete function PrintPopcornTime(), with int parameter bagOunces, and void return type. If bagOunces is less than 3, print "To
    9·1 answer
  • The expression 10,785(1.0275)x represents the amount of money in an investment account with interest that compounds annually for
    14·2 answers
  • Which of the following is true of standard error? a. It can take negative values. b. It is an estimate of the standard deviation
    6·1 answer
  • I need help ASAP please and thank you!
    6·1 answer
  • Which steps are correct for creating a document from a user-defined template?
    15·1 answer
  • What is the most common type of storage device for transferring files from one computer to another?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!