Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Carefully and completely read and answer the following questions. Make certain y

ID: 2247734 • Letter: C

Question

Carefully and completely read and answer the following questions. Make certain your answers are clear and complete for full credit. 1. ArrayLists a) Write a Java statement to declare and create an ArrayList to hold Integers. b) Write Java statements to add the integers 1011, 1101, and 1110 to the resulting ArrayList from question 1.a above. c) Write a Java statement to display the current size of (number of items in) the resulting ArrayList from question 1.b above. d) Write Java statements that use an enhanced for (for-each) loop to cycle through all the elements in an ArrayList of doubles named grades. You may assume that the grades ArrayList has been declared, created and initialized with double values.

Explanation / Answer

1a) ArrayList<Integer> demo = new ArrayList<Integer>();

1b)

import java.util.ArrayList;

public class temp {

public static void main(String args[]) {

ArrayList<Integer> demo = new ArrayList<Integer>();

demo.add(1011);

demo.add(1101);

demo.add(1110);

}

}

1c) System.out.println("arraylist size is " +demo.size());

1d)

for (Iterator<Double> iterator = al.iterator(); iterator.hasNext();) {

Double obj = iterator.next();

}

or

for(Double obj:al) {

}

here al is the arraylist declared with double values