This topic contains a solution. Click here to go to the answer

Author Question: Suppose an ArrayList list contains {"red", "red", "green"}. What is the list after the following ... (Read 32 times)

vicky

  • Hero Member
  • *****
  • Posts: 586

Question 1

Suppose an ArrayList list contains {"red", "red", "green"}. What is the list after the following code?

String element = "red";
for (int i = 0; i < list.size(); i++)
if (list.get(i).equals(element)) {
list.remove(element);
i--;
}

◦ {"green"}
◦ {"red", "green"}
◦ {}
◦ {"red", "red", "green"}

Question 2

Suppose an ArrayList list contains {"red", "red", "green"}. What is the list after the following code?

String element = "red";
for (int i = list.size() - 1; i >= 0; i--)
if (list.get(i).equals(element))
list.remove(element);

◦ {"red", "red", "green"}
◦ {}
◦ {"green"}
◦ {"red", "green"}


Related Topics

Need homework help now?

Ask unlimited questions for free

Ask a Question
Marked as best answer by vicky on May 6, 2020

meryzewe

  • Sr. Member
  • ****
  • Posts: 346
Lorsum iprem. Lorsus sur ipci. Lorsem sur iprem. Lorsum sur ipdi, lorsem sur ipci. Lorsum sur iprium, valum sur ipci et, vala sur ipci. Lorsem sur ipci, lorsa sur iprem. Valus sur ipdi. Lorsus sur iprium nunc, valem sur iprium. Valem sur ipdi. Lorsa sur iprium. Lorsum sur iprium. Valem sur ipdi. Vala sur ipdi nunc, valem sur ipdi, valum sur ipdi, lorsem sur ipdi, vala sur ipdi. Valem sur iprem nunc, lorsa sur iprium. Valum sur ipdi et, lorsus sur ipci. Valem sur iprem. Valem sur ipci. Lorsa sur iprium. Lorsem sur ipci, valus sur iprem. Lorsem sur iprem nunc, valus sur iprium.
Answer Preview
Only 50% of students answer this correctly




vicky

  • Member
  • Posts: 586
Reply 2 on: May 6, 2020
Excellent


DylanD1323

  • Member
  • Posts: 314
Reply 3 on: Yesterday
YES! Correct, THANKS for helping me on my review

 

Did you know?

A good example of polar molecules can be understood when trying to make a cake. If water and oil are required, they will not mix together. If you put them into a measuring cup, the oil will rise to the top while the water remains on the bottom.

Did you know?

More than nineteen million Americans carry the factor V gene that causes blood clots, pulmonary embolism, and heart disease.

Did you know?

There are 60,000 miles of blood vessels in every adult human.

Did you know?

There are more bacteria in your mouth than there are people in the world.

Did you know?

It is widely believed that giving a daily oral dose of aspirin to heart attack patients improves their chances of survival because the aspirin blocks the formation of new blood clots.

For a complete list of videos, visit our video library