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 157 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
Excellent


raenoj

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

 

Did you know?

The heart is located in the center of the chest, with part of it tipped slightly so that it taps against the left side of the chest.

Did you know?

Cytomegalovirus affects nearly the same amount of newborns every year as Down syndrome.

Did you know?

The cure for trichomoniasis is easy as long as the patient does not drink alcoholic beverages for 24 hours. Just a single dose of medication is needed to rid the body of the disease. However, without proper precautions, an individual may contract the disease repeatedly. In fact, most people develop trichomoniasis again within three months of their last treatment.

Did you know?

Since 1988, the CDC has reported a 99% reduction in bacterial meningitis caused by Haemophilus influenzae, due to the introduction of the vaccine against it.

Did you know?

About 60% of newborn infants in the United States are jaundiced; that is, they look yellow. Kernicterus is a form of brain damage caused by excessive jaundice. When babies begin to be affected by excessive jaundice and begin to have brain damage, they become excessively lethargic.

For a complete list of videos, visit our video library