What is the output of the following code?
ArrayList<Integer> list = new ArrayList<>();
list.add(5);
list.add(10);
list.add(15);
list.remove(1);
System.out.println(list);
Loading test…
12 questions
What is the output of the following code?
ArrayList<Integer> list = new ArrayList<>();
list.add(5);
list.add(10);
list.add(15);
list.remove(1);
System.out.println(list);
What is the output of the following code?
ArrayList<Double> list = new ArrayList<>();
list.add(1.5);
list.add(2.5);
list.add(3.5);
double sum = 0;
for (double d : list) {
sum += d;
}
System.out.println(sum);
What is the output of the following code?
ArrayList<Integer> list = new ArrayList<>();
for (int i = 1; i <= 5; i++) {
list.add(i);
}
for (int i = 0; i < list.size(); i++) {
System.out.print(list.get(i) + " ");
}
What is the output of the following code?
ArrayList<Integer> list = new ArrayList<>();
list.add(100);
list.add(200);
list.set(0, 999);
System.out.println(list.get(0));
System.out.println(list.size());
Which of the following correctly removes all elements equal to 0 from an ArrayList without skipping elements?
ArrayList<Integer> list = new ArrayList<>();
// list contains: [0, 5, 0, 3, 0]
What is the output of the following code?
import java.util.ArrayList;
ArrayList<Integer> list = new ArrayList<>();
list.add(10);
list.add(20);
list.add(30);
System.out.println(list.size());
System.out.println(list.get(1));
What is the state of list after the following code executes?
ArrayList<String> list = new ArrayList<>();
list.add("A");
list.add("B");
list.add("C");
list.add(1, "X");
What is the output of the following code?
ArrayList<Integer> list = new ArrayList<>();
list.add(1);
list.add(2);
list.add(3);
list.add(4);
for (int i = 0; i < list.size(); i++) {
if (list.get(i) % 2 == 0) {
list.remove(i);
}
}
System.out.println(list);
What is the output of the following code?
ArrayList<String> list = new ArrayList<>();
list.add("apple");
list.add("banana");
list.add("cherry");
String result = "";
for (int i = list.size() - 1; i >= 0; i--) {
result += list.get(i).charAt(0);
}
System.out.println(result);
What is the output of the following code?
ArrayList<Integer> list = new ArrayList<>();
for (int i = 0; i < 5; i++) {
list.add(i * 2);
}
list.remove(Integer.valueOf(4));
System.out.println(list);
What is the output of the following code?
ArrayList<String> list = new ArrayList<>();
list.add("dog");
list.add("cat");
list.add("dog");
list.add("bird");
int count = 0;
for (String s : list) {
if (s.equals("dog")) count++;
}
System.out.println(count);
What is the output of the following code?
ArrayList<Integer> a = new ArrayList<>();
a.add(1); a.add(2); a.add(3);
ArrayList<Integer> b = new ArrayList<>(a);
b.add(4);
System.out.println(a.size());
System.out.println(b.size());