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

Author Question: Analyze the following code: Double[] array = {1, 2, 3}; ArrayList list = new ... (Read 155 times)

dejastew

  • Hero Member
  • *****
  • Posts: 562

Question 1

Show the output of the following code:

String[] array = {"red", "green", "blue"};
ArrayList list = new ArrayList<>(Arrays.asList(array));
list.add(0, "red");
System.out.println(list);

◦ ["red", "green", "blue"]
◦ ["red", "red", "green", "blue"]
◦ ["red", "green", "blue", "red"]
◦ ["red", "green", "red", "blue"]

Question 2

Analyze the following code:

Double[] array = {1, 2, 3};
ArrayList list = new ArrayList<>(Arrays.asList(array));
System.out.println(list);

◦ The code is correct and displays [1, 2, 3].
◦ The code is correct and displays [1.0, 2.0, 3.0].
◦ The code has a compile error because asList(array) requires that the array elements are objects.

◦ The code has a compile error because an integer such as 1 is automatically converted into an Integer object, but the array element type is Double.


Related Topics

Need homework help now?

Ask unlimited questions for free

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

chreslie

  • Sr. Member
  • ****
  • Posts: 307
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 25% of students answer this correctly




dejastew

  • Member
  • Posts: 562
Reply 2 on: May 6, 2020
YES! Correct, THANKS for helping me on my review


blakcmamba

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

 

Did you know?

Cocaine was isolated in 1860 and first used as a local anesthetic in 1884. Its first clinical use was by Sigmund Freud to wean a patient from morphine addiction. The fictional character Sherlock Holmes was supposed to be addicted to cocaine by injection.

Did you know?

Critical care patients are twice as likely to receive the wrong medication. Of these errors, 20% are life-threatening, and 42% require additional life-sustaining treatments.

Did you know?

Certain chemicals, after ingestion, can be converted by the body into cyanide. Most of these chemicals have been removed from the market, but some old nail polish remover, solvents, and plastics manufacturing solutions can contain these substances.

Did you know?

About 100 new prescription or over-the-counter drugs come into the U.S. market every year.

Did you know?

The familiar sounds of your heart are made by the heart's valves as they open and close.

For a complete list of videos, visit our video library