0% found this document useful (0 votes)
10 views2 pages

Java Collections Interview Questions

The document outlines a comprehensive set of interview questions and answers related to the Java Collections Framework, covering basic concepts, lists, sets, maps, algorithms, coding challenges, and conceptual questions. It addresses key differences between various collection types, internal workings, and practical coding scenarios. This resource serves as a guide for individuals preparing for interviews focused on Java collections.

Uploaded by

cglprep9
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views2 pages

Java Collections Interview Questions

The document outlines a comprehensive set of interview questions and answers related to the Java Collections Framework, covering basic concepts, lists, sets, maps, algorithms, coding challenges, and conceptual questions. It addresses key differences between various collection types, internal workings, and practical coding scenarios. This resource serves as a guide for individuals preparing for interviews focused on Java collections.

Uploaded by

cglprep9
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Java Collections Framework — Interview

Questions & Answers

1. Basic Concept Questions


1 What is a Collection in Java?
2 Difference between Collection and Collections.
3 Main interfaces in the Java Collections Framework.
4 Difference between List, Set, and Map.
5 Why use Collections instead of arrays?

2. List-related Questions
1 Difference between ArrayList and LinkedList.
2 How does ArrayList grow internally?
3 How to make an ArrayList synchronized?
4 Can we store null elements in ArrayList or LinkedList?
5 Which is faster — ArrayList or LinkedList — and why?
6 Ways to iterate over a list (Iterator, for-each, Stream, etc.).

3. Set-related Questions
1 Difference between HashSet, LinkedHashSet, and TreeSet.
2 How does HashSet internally work?
3 Can HashSet contain duplicate elements?
4 How does TreeSet maintain order?
5 What happens if we insert null in TreeSet?

4. Map-related Questions
1 Difference between HashMap and Hashtable.
2 How does HashMap work internally?
3 What is collision in HashMap, and how is it resolved?
4 Difference between HashMap and LinkedHashMap.
5 What is ConcurrentHashMap and how it differs from HashMap.
6 Can we have null key or value in HashMap or Hashtable?

5. Algorithm & Behavior Questions


1 How does [Link]() work?
2 How to make a collection read-only?
3 Difference between fail-fast and fail-safe iterators.
4 How to synchronize a collection manually?
5 Difference between Iterator and ListIterator.
6 How to remove elements safely while iterating?

6. Coding-based Questions
1 Remove duplicates from a list using Set.
2 Count occurrences of each word in a string using Map.
3 Sort a Map by its values.
4 Convert a HashMap to a TreeMap.
5 Find the first non-repeated character in a string using Map.
6 Handle concurrent modifications in a collection.

7. Conceptual Tricky Questions


1 Why override equals() and hashCode() for custom objects in HashSet/HashMap?
2 What happens if hashCode() returns the same value for two different objects?
3 Difference between Comparable and Comparator.
4 Difference between Enumeration, Iterator, and ListIterator.
5 Can we sort a HashMap? How?

You might also like