SET 6 – Collections Fundamentals
Q1. What is the output?
List<Integer> list =
Arrays.asList(10,20,30);
System.out.println(list.get(1));
A. 10
B. 20
C. 30
D. Exception
Q2. What is the output?
Set<Integer> set =
new HashSet<>();
set.add(10);
set.add(20);
set.add(10);
System.out.println(set.size());
A. 1
B. 2
C. 3
D. Exception
Q3. What is the output?
Map<String,Integer> map =
new HashMap<>();
map.put(“A”,1);
map.put(“A”,5);
System.out.println(map.get(“A”));
A. 1
B. 5
C. null
D. Exception
Q4. What is the output?
Queue<Integer> q =
new LinkedList<>();
q.offer(10);
q.offer(20);
System.out.println(q.poll());
A. 10
B. 20
C. null
D. Exception
Q5. What is the output?
Stack<Integer> stack =
new Stack<>();
stack.push(10);
stack.push(20);
System.out.println(stack.pop());
A. 10
B. 20
C. Exception
D. null
Q6. What is the output?
List<Integer> list =
Arrays.asList(1,2,3);
list.add(4);
A. Size becomes 4
B. Compilation Error
C. UnsupportedOperationException
D. NullPointerException
Q7. Insert missing code.
List<Integer> list =
Arrays.asList(10,20,30);
___________
System.out.println(sum);
Desired Output:
60
A.
int sum =
list.stream()
.mapToInt(Integer::intValue)
.sum();
B.
sum(list);
C.
list.sum();
D.
int sum = 0;
Q8. What happens?
Iterator<Integer> itr =
list.iterator();
while(itr.hasNext()) {
list.add(10);
}
A. Infinite Loop
B. ConcurrentModificationException
C. Compilation Error
D. Works successfully
Q9. Average lookup complexity of HashMap?
A. O(1)
B. O(log n)
C. O(n)
D. O(n²)
Q10. Which collection follows FIFO?
A. Stack
B. Queue
C. TreeSet
D. HashMap
Answers – SET 6
| Q | Answer | Explanation |
| 1 | B | Index starts at 0. |
| 2 | B | Set removes duplicates. |
| 3 | B | New value replaces old value. |
| 4 | A | Queue is FIFO. |
| 5 | B | Stack is LIFO. |
| 6 | C | Arrays.asList returns fixed-size list. |
| 7 | A | Stream sum operation. |
| 8 | B | Structural modification during iteration. |
| 9 | A | Average constant lookup. |
| 10 | B | Queue is FIFO. |
SET 7 – HashMap, TreeMap and Sorting
Q1. Output?
Map<Integer,String> map =
new TreeMap<>();
map.put(3,”C”);
map.put(1,”A”);
map.put(2,”B”);
System.out.println(map);
A. {3=C,1=A,2=B}
B. {1=A,2=B,3=C}
C. Exception
D. Random order
Q2. Output?
List<Integer> list =
Arrays.asList(30,10,20);
Collections.sort(list);
System.out.println(list);
A. [30,10,20]
B. [10,20,30]
C. Exception
D. Random order
Q3. Output?
PriorityQueue<Integer> pq =
new PriorityQueue<>();
pq.offer(30);
pq.offer(10);
pq.offer(20);
System.out.println(pq.poll());
A. 30
B. 20
C. 10
D. Exception
Q4. Output?
Set<Integer> set =
new TreeSet<>();
set.add(30);
set.add(10);
set.add(20);
System.out.println(set);
A. [30,10,20]
B. [10,20,30]
C. Exception
D. Random order
Q5. Output?
List<String> list =
Arrays.asList(“B”,”A”,”C”);
Collections.reverse(list);
System.out.println(list);
A. [A,B,C]
B. [C,A,B]
C. [B,A,C]
D. Exception
Q6. Output?
Map<Integer,String> map =
new HashMap<>();
System.out.println(map.get(10));
A. Exception
B. 0
C. null
D. Empty
Q7. Insert code.
Collections.sort(list,
___________);
Sort descending.
A.
Collections.reverseOrder()
B.
Comparator.asc()
C.
sortDesc()
D.
Comparator.reverse()
Q8. What happens?
TreeSet<Object> set =
new TreeSet<>();
set.add(10);
set.add(“A”);
A. Works
B. Compilation Error
C. ClassCastException
D. NullPointerException
Q9. Complexity of Collections.sort()?
A. O(n)
B. O(log n)
C. O(n log n)
D. O(n²)
Q10. Which interface supports custom sorting?
A. Runnable
B. Predicate
C. Comparator
D. Supplier
Answers – SET 7
| Q | Answer |
| 1 | B |
| 2 | B |
| 3 | C |
| 4 | B |
| 5 | B |
| 6 | C |
| 7 | A |
| 8 | C |
| 9 | C |
| 10 | C |
SET 8 – Streams, Concurrent Collections and Algorithms
Q1. Output?
List<Integer> list =
Arrays.asList(1,2,3,4);
long count =
list.stream()
.filter(x -> x % 2 == 0)
.count();
System.out.println(count);
A. 1
B. 2
C. 3
D. 4
Q2. Output?
List<String> list =
Arrays.asList(“A”,”B”);
list.stream()
.map(String::toLowerCase)
.forEach(System.out::print);
A. AB
B. ab
C. a b
D. Exception
Q3. Output?
ConcurrentHashMap<Integer,String> map =
new ConcurrentHashMap<>();
map.put(1,”A”);
System.out.println(map.get(1));
A. null
B. A
C. Exception
D. 1
Q4. Output?
Deque<Integer> dq =
new ArrayDeque<>();
dq.push(10);
dq.push(20);
System.out.println(dq.pop());
A. 10
B. 20
C. Exception
D. null
Q5. Output?
List<Integer> list =
Arrays.asList(10,20,30);
System.out.println(
list.contains(20));
A. true
B. false
C. Exception
D. null
Q6. Output?
Map<String,Integer> map =
Map.of(“A”,1,”B”,2);
map.put(“C”,3);
A. Works
B. Compilation Error
C. UnsupportedOperationException
D. NullPointerException
Q7. Insert code.
List<Integer> list =
Arrays.asList(10,20,30);
__________
Desired output:
60
A.
System.out.println(
list.stream()
.reduce(0,Integer::sum));
B.
list.total();
C.
sum(list);
D.
list.sum();
Q8. What happens?
ConcurrentHashMap<Integer,Integer> map =
new ConcurrentHashMap<>();
map.put(null,1);
A. Works
B. Compilation Error
C. NullPointerException
D. Runtime Exception
Q9. Which algorithm uses Stack internally?
A. BFS
B. DFS
C. Dijkstra
D. Binary Search
Q10. Complexity of ArrayList get(index)?
A. O(1)
B. O(log n)
C. O(n)
D. O(n²)
Answers – SET 8
| Q | Answer | Explanation |
| 1 | B | Two even numbers. |
| 2 | B | Stream converts to lowercase. |
| 3 | B | Value retrieved successfully. |
| 4 | B | Deque behaves as stack. |
| 5 | A | Element exists. |
| 6 | C | Map.of creates immutable map. |
| 7 | A | Reduce computes sum. |
| 8 | C | ConcurrentHashMap disallows null keys. |
| 9 | B | Depth First Search uses stack. |
| 10 | A | ArrayList supports random access. |
Interviewer Notes
SET 6
Evaluates:
- Basic collections
- Queue/Stack understanding
- Iterator behavior
SET 7
Evaluates:
- Sorting
- TreeMap
- Comparator
- PriorityQueue
SET 8
Evaluates:
- Streams
- Concurrent collections
- Immutable collections
- Algorithm selection
Difficulty Matrix
| Set | Level |
| Set 1 | Easy |
| Set 2 | Easy-Medium |
| Set 3 | Medium |
| Set 4 | Medium |
| Set 5 | Medium-Hard |
| Set 6 | Medium |
| Set 7 | Medium-Hard |
| Set 8 | Hard |
Final Assessment
| Score | Rating |
| 72–80 | Outstanding Java Engineer |
| 60–71 | Strong Java Developer |
| 45–59 | Good Fundamentals |
| 30–44 | Average |
| Below 30 | Needs Training |
A candidate scoring above 65/80 generally demonstrates strong knowledge of Core Java, Collections, Java 8, and problem-solving skills that are expected from enterprise Java developers and senior interview candidates.