Question 1mediummultiple choice
Read the full Working with Arrays and Collections explanation →1Z0-829 Working with Arrays and Collections • Complete Question Bank
Complete 1Z0-829 Working with Arrays and Collections question bank — all 0 questions with answers and detailed explanations.
Refer to the exhibit.
$ cat list.txt
A
B
C
D
$ cat ListDemo.java
import java.util.*;
import java.util.stream.*;
public class ListDemo {
public static void main(String[] args) {
List<String> list = new ArrayList<>(List.of("A", "B", "C", "D"));
list.removeIf(s -> s.compareTo("C") > 0);
System.out.println(list);
}
}
$ javac ListDemo.java && java ListDemoRefer to the exhibit.
Error log:
Exception in thread "main" java.lang.ClassCastException: class java.lang.Integer cannot be cast to class java.lang.String
at com.example.Cache.get(Cache.java:12)
at com.example.Main.main(Main.java:10)
Source code:
public class Cache {
private Map<String, Object> store = new HashMap<>();
public <T> T get(String key, Class<T> type) {
Object value = store.get(key);
return type.cast(value);
}
}
public class Main {
public static void main(String[] args) {
Cache cache = new Cache();
cache.store.put("age", 30);
String age = cache.get("age", String.class);
System.out.println(age);
}
}Refer to the exhibit.
```
List<String> list = new ArrayList<>(List.of("A", "B", "C"));
for (String s : list) {
if (s.equals("B")) {
list.remove(s);
}
}
System.out.println(list);
```Drag steps to the numbered slots on the right, or tap a step then tap a slot.
Drag a concept onto its matching description — or click a concept then click the description.
Resizable array
Doubly linked list
Hash table
Red-black tree
Hash table with buckets
Which of the following correctly describes the behavior of the following code? List<String> list = new ArrayList<>(); list.add("A"); list.add("B");
for (String s : list) {
if (s.equals("A")) {list.remove(s);
} }
System.out.println(list);
Refer to the exhibit.
List<String> list = new ArrayList<>(List.of("a","b","c"));
list.removeIf(s -> s.equals("b"));
System.out.println(list);Refer to the exhibit.
List<String> list = new ArrayList<>();
list.add("A");
List<?> list2 = list;
list2.add("B");
System.out.println(list2);Refer to the exhibit.
```java
import java.util.*;
import java.util.stream.*;
public class Test {
public static void main(String[] args) {
List<String> list = List.of("a", "b", "c");
var result = list.stream()
.filter(s -> s.startsWith("b"))
.collect(Collectors.toUnmodifiableList());
result.add("d");
System.out.println(result);
}
}
```