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 30 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
Wow, this really help


bimper21

  • Member
  • Posts: 309
Reply 3 on: Yesterday
Thanks for the timely response, appreciate it

 

Did you know?

Street names for barbiturates include reds, red devils, yellow jackets, blue heavens, Christmas trees, and rainbows. They are commonly referred to as downers.

Did you know?

About 80% of major fungal systemic infections are due to Candida albicans. Another form, Candida peritonitis, occurs most often in postoperative patients. A rare disease, Candida meningitis, may follow leukemia, kidney transplant, other immunosuppressed factors, or when suffering from Candida septicemia.

Did you know?

The most common treatment options for addiction include psychotherapy, support groups, and individual counseling.

Did you know?

Cucumber slices relieve headaches by tightening blood vessels, reducing blood flow to the area, and relieving pressure.

Did you know?

The word drug comes from the Dutch word droog (meaning "dry"). For centuries, most drugs came from dried plants, hence the name.

For a complete list of videos, visit our video library