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 29 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
YES! Correct, THANKS for helping me on my review


bdobbins

  • Member
  • Posts: 326
Reply 3 on: Yesterday
Gracias!

 

Did you know?

A cataract is a clouding of the eyes' natural lens. As we age, some clouding of the lens may occur. The first sign of a cataract is usually blurry vision. Although glasses and other visual aids may at first help a person with cataracts, surgery may become inevitable. Cataract surgery is very successful in restoring vision, and it is the most frequently performed surgery in the United States.

Did you know?

Bacteria have been found alive in a lake buried one half mile under ice in Antarctica.

Did you know?

Approximately 70% of expectant mothers report experiencing some symptoms of morning sickness during the first trimester of pregnancy.

Did you know?

About 600,000 particles of skin are shed every hour by each human. If you live to age 70 years, you have shed 105 pounds of dead skin.

Did you know?

The top five reasons that children stay home from school are as follows: colds, stomach flu (gastroenteritis), ear infection (otitis media), pink eye (conjunctivitis), and sore throat.

For a complete list of videos, visit our video library