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
Hi can someone help me make a like a song for music Class pls I attached an example of what i need.
g100num [7]

Answer:

i dont really like music so sorry i cant help i hope someone can help you with this.

8 0
3 years ago
Assume inputFile is a Scanner object used to read data from a text file that contains a number of lines. Each line contains an a
anzhelika [568]

Answer:

words.hasNext()

Explanation:

Given the code snippet below:

  1.        while (inputFile.hasNextLine()) {
  2.            String word = "";
  3.            String line = inputFile.nextLine();
  4.            Scanner words = new Scanner(line);
  5.            while (words.hasNext()) {
  6.                word = words.next();
  7.            }
  8.            System.out.println(word); }
  9.    }

We have a inputFile Scanner object that can read data from a text file and we presume the inputFile has read several rows of data from the text file. So long as there is another line of input data available, the outer while loop will keep running. In each outer loop, one line of data will be read and assign to line variable (Line 3). Next, there is another Scanner object, words, which will take the current line of data as input. To get the last word of that line, we can use hasNext() method. This method will always return true if there is another tokens in its input. So the inner while loop will keep running so long as there is a token in current line of data and assign the current token to word variable. The word will hold the last token of current line of data upon exit from the inner loop. Then we can print the output (Line 8) which is the last word of the current line of data.

7 0
3 years ago
Are psn cd keys region free? If not where can I get one in my region?
Andrews [41]
This isn't school related but I'm still gonna help you so you should check the location to see if it's set to be in China if it isn't change it to China if that doesn't work I would just recommend calling customer service if you can.
3 0
3 years ago
Read 2 more answers
HELP ASAP
CaHeK987 [17]
The answer is B, e commerce. Have a good day
3 0
3 years ago
You are to write a program name elevator.java that simulates one elevator services in a 12-floor building. note: there is only o
gogolik [260]
See the attachment, if I copy if it into the Response field it gets all jumbled. Rename it to elevator.java
Download txt
5 0
3 years ago
Other questions:
  • If robots can work 24 hours a day, 365 days of the year,how many hours and days can humans work.
    12·2 answers
  • What is credibility in the often-used framework of quality criteria?
    9·1 answer
  • Alright, so im currently trying to pass a computer science class. i need it done in a little under 2 weeks. Ill just ask the one
    5·1 answer
  • Write a program that lets the user enter a nonnegative integer then uses a loop to calculate the factorial of that number. Displ
    11·1 answer
  • Mad Libs are activities that have a person provide various words, which are then used to complete a short story in unexpected (a
    14·1 answer
  • A cpu handless all the instruction that it recieces from hard ware and software which are available on the computer true or fals
    7·1 answer
  • Karl comes across confidential information. What should he do with it? A. Manipulate the information in his favor B. Sell the in
    12·1 answer
  • 1. What are you going to do if someone ask for your personal information online?​
    12·2 answers
  • Which of the following is an example of a stereotype?
    11·1 answer
  • How does a security information and event management system (SIEM) in a SOC help the personnel fight against security threats
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!