Ask Question

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);

+3
Answers (1)
  1. 14 June, 06:34
    0
    The output of the given code as follows:

    Output:

    {"red", "green"}

    Explanation:

    In the given code a list is defined, which contains three elements, which are "red, red, and green". In the next step, a string variable "element" is initialized with a value that is "red". Then a for loop is declared, that counts list size, and inside the loop and if block is declared, that compares the value list with element variable then it removes from the list.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Suppose an ArrayList list contains {"red", "red", "green"}. What is the list after the following code? String element = "red"; for (int i = ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers