Collection Framework, List, Set, Map

Core Collection Framework: List, Set and Map interfaces and their implementations.


Collection is the root interface: List (duplicates allowed), Set (no duplicates), Queue; Map is separate (key-value pairs). ArrayList is a resizable array with fast access; LinkedList is doubly-linked. HashSet is unordered, LinkedHashSet ordered by insertion, TreeSet sorts elements; HashMap is unordered, LinkedHashMap ordered by insertion, TreeMap sorts keys. Generics like List add compile-time safety; autoboxing converts int to Integer.

Example
List < String > l = new ArrayList <>();
Map < String, Integer > m = new HashMap <>();
Video Lesson Open in new tab
Quiz
1. Which of these interfaces is NOT part of the Collection interface hierarchy?
2. Which collection accepts duplicate elements and preserves insertion order as you add them?
3. Which List implementation is backed by a resizable array and offers fast constant-time access by index?
4. Which Set implementation keeps its elements sorted according to their natural ordering?
5. Which statement about a HashMap is correct?
6. When a TreeMap is created without a Comparator, how does it order its entries?
Coding Problems
1. Write a Java program that counts how many times each word appears in the array {"java","is","java"} using a HashMap and prints the count for the word "java".
Discussion

Login to join the discussion.


No comments yet.