11 questions
What is the ArrayList nums if it is initially [5, 3, 1] and the following code is executed?
nums.add(6);
nums.add(0, 4);
nums.remove(1);
[4, 3, 1, 6]
[5, 3, 1, 6]
[4, 3, 6]
[4, 5, 3, 6]
What index value is used to locate the last element in the nums ArrayList?
nums.size()-1
nums.length()-1
nums.size()
nums.length
Which statement below is the correct way to retrieve the first element in the nums ArrayList?
nums.get(0)
nums[0]
nums(0)
nums[1]
Given the ArrayList nums with the values [3, 7, 6, 0], what code below is the proper way to change the 7 to be a 5?
nums.set(1, 5)
nums.set(7, 5)
nums.set(5, 2)
nums[2] = 5
Given the nums ArrayList with the values [5, 4, 3, 2], what statement below removes the value 3 from the list?
nums.remove(2)
nums.remove(3)
nums.get(2) = null
nums.remove(1)
Given the nums ArrayList with the values [1, 2, 3, 4, 6], what code below can be used to add a 5 between the 4 and 6 in the list?
nums.add(4, 5)
nums.add(5, 4)
nums.add(5, 5)
nums.add(5)
What will print when the following code executes?
ArrayList<Integer> list = new ArrayList<Integer>();
list.add(7);
list.add(8);
list.add(9);
System.out.println(list.remove(0));
7
8
9
0
What is printed?
ArrayList<Integer> alist;
alist = new ArrayList<Integer>();
alist.add(1);
alist.add(2);
alist.remove(1);
alist.add(1, 3);
alist.set(1, 4);
alist.add(5);
System.out.println(alist);
[1, 4, 5]
[1, 4, 3, 5]
[2, 4, 5]
[2, 4, 3, 5]
What is printed?
ArrayList<Double> vals;
vals = new ArrayList<Double>();
vals.add(3.5);
vals.add(4.5);
vals.add(5.5);
vals.set(0, 2.5) ;
System.out.println(vals);
[2.5, 4.5, 5.5, 3.5]
[2.5, 3.5, 4.5, 5.5]
[3.5, 4.5, 5.5, 2.5]
[2.5, 4.5, 5.5]
Which statement is the correct declaration and initialization of an ArrayList of String values?
ArrayList<String> name;
name = new ArrayList<String>();
ArrayList name;
name = new ArrayList<String>();
ArrayList<String> name;
name = ArrayList<String>();
String<ArrayList> name;
name = new String<ArrayList>();
What is printed after executing code on the nums ArrayList with the values [3, 2, 4, 5, 7]?
7
5
6
memory full because too many values added