Subjects

All subjects Django Java Python React Spring Boot JavaScript PHP
Sign Up Free
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.

InterfaceAllows duplicates?Ordered?Key implementations
ListYesYes (insertion order)ArrayList, LinkedList
SetNoDepends on implHashSet, LinkedHashSet, TreeSet
MapKeys unique, values can repeatDepends on implHashMap, LinkedHashMap, TreeMap
QueueYesYes (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 देता है।

InterfaceDuplicates?Ordered?Implementations
ListहाँहाँArrayList, LinkedList
SetनहींImplementation पर dependHashSet, TreeSet
MapKeys uniqueImplementation पर dependHashMap, 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?