Interview question
What is the Java Collections Framework and what are its core interfaces? Java Collections Framework क्या है और इसके core interfaces क्या हैं?
Answer
The Collections Framework is a unified architecture for storing and manipulating groups of objects, providing standard interfaces, implementations, and algorithms.
| Interface | Allows duplicates? | Ordered? | Key implementations |
|---|---|---|---|
| List | Yes | Yes (insertion order) | ArrayList, LinkedList |
| Set | No | Depends on impl | HashSet, LinkedHashSet, TreeSet |
| Map | Keys unique, values can repeat | Depends on impl | HashMap, LinkedHashMap, TreeMap |
| Queue | Yes | Yes (FIFO typically) | LinkedList, PriorityQueue |
List<String> list = new ArrayList<>();
list.add('A');
list.add('B');
Set<String> set = new HashSet<>();
set.add('A');
set.add('A'); // ignored, duplicates not allowed
Map<String, Integer> map = new HashMap<>();
map.put('age', 30);
map.put('age', 31); // overwrites previous value
System.out.println(list); // [A, B]
System.out.println(set); // [A]
System.out.println(map); // {age=31}Collections Framework objects के groups को store और manipulate करने के लिए unified architecture देता है।
| Interface | Duplicates? | Ordered? | Implementations |
|---|---|---|---|
| List | हाँ | हाँ | ArrayList, LinkedList |
| Set | नहीं | Implementation पर depend | HashSet, TreeSet |
| Map | Keys unique | Implementation पर depend | HashMap, TreeMap |
List<String> list = new ArrayList<>();
list.add('A');
list.add('B');
Set<String> set = new HashSet<>();
set.add('A');
set.add('A'); // ignore हो जाता है
Map<String, Integer> map = new HashMap<>();
map.put('age', 30);
map.put('age', 31); // overwrite होता है
System.out.println(list);
System.out.println(set);
System.out.println(map);Was this answer clear?