Unit 7: ArrayList

Showing 17 of 17 questions

Q1
MULTIPLE_CHOICEEasy

What is the output of the following code?

Q2
MULTIPLE_CHOICEHard

What is the output of the following code?

Q3
MULTIPLE_CHOICEMedium

What is the output of the following code?

Q4
MULTIPLE_CHOICEMedium

Which of the following correctly removes all even numbers from an ArrayList<Integer> named nums?

Q5
MULTIPLE_CHOICEHard

What is the output of the following code?

Q6
MULTIPLE_CHOICEMedium

What is the output of the following code?

Q7
MULTIPLE_CHOICEMedium

What is the output of the following code?

Q8
MULTIPLE_CHOICEMedium

Which of the following correctly declares an ArrayList of integers and adds the value 42?

Q9
MULTIPLE_CHOICEMedium

After the following code, what is the size of the list?\nArrayList<String> list = new ArrayList<String>();\nlist.add("A");\nlist.add("B");\nlist.add("C");\nlist.remove(1);

Q10
MULTIPLE_CHOICEMedium

Which is true about ArrayList compared to arrays?

Q11
MULTIPLE_CHOICEMedium

ArrayList<Integer> stores Integer objects. Given: list.add(5), how is 5 stored?

Q12
MULTIPLE_CHOICEMedium

Given list = [A, B, C, D], what is the list after list.set(2, "X")?

Q13
MULTIPLE_CHOICEHard

When removing elements from an ArrayList during traversal with a forward for loop, what common error occurs?

Q14
MULTIPLE_CHOICEMedium

Given list = [A, B, D], what is the result of list.add(2, "C")?

Q15
MULTIPLE_CHOICEHard

What is the output?\nArrayList<Integer> list = new ArrayList<>();\nfor (int i = 0; i < 5; i++) list.add(i);\nfor (int i = 0; i < list.size(); i++) if (list.get(i) % 2 == 0) list.remove(i);\nSystem.out.println(list);

Q16
MULTIPLE_CHOICEHard

Consider the following code segment. \nArrayList<Integer> list = new ArrayList<>();\nfor (int i = 1; i <= 5; i++) list.add(i * 10);\nfor (int i = list.size() - 1; i >= 0; i--) { if (list.get(i) % 20 == 0) { list.remove(i); } }\nSystem.out.println(list);

Q17
MULTIPLE_CHOICEHard

What is the output? ArrayList<Integer> list = new ArrayList<>(); for (int i = 0; i < 6; i++) list.add(i * 2); for (int i = list.size() - 1; i >= 0; i--) { if (list.get(i) % 4 == 0) list.remove(i); } System.out.println(list);

Advertisement