Java Collections and Algorithms Assessment

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

QAnswerExplanation
1BIndex starts at 0.
2BSet removes duplicates.
3BNew value replaces old value.
4AQueue is FIFO.
5BStack is LIFO.
6CArrays.asList returns fixed-size list.
7AStream sum operation.
8BStructural modification during iteration.
9AAverage constant lookup.
10BQueue 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

QAnswer
1B
2B
3C
4B
5B
6C
7A
8C
9C
10C

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

QAnswerExplanation
1BTwo even numbers.
2BStream converts to lowercase.
3BValue retrieved successfully.
4BDeque behaves as stack.
5AElement exists.
6CMap.of creates immutable map.
7AReduce computes sum.
8CConcurrentHashMap disallows null keys.
9BDepth First Search uses stack.
10AArrayList 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

SetLevel
Set 1Easy
Set 2Easy-Medium
Set 3Medium
Set 4Medium
Set 5Medium-Hard
Set 6Medium
Set 7Medium-Hard
Set 8Hard

Final Assessment

ScoreRating
72–80Outstanding Java Engineer
60–71Strong Java Developer
45–59Good Fundamentals
30–44Average
Below 30Needs 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.

Leave a Reply

Your email address will not be published. Required fields are marked *