All fields

“Collections Framework” in Information Technology

46 questions across 2 technologies.

Information Technology

46 questions in 2 technologies

#QuestionTechnologyTopicLevel
1What is the Java Collections Framework, and what are the core interfaces (List, Set, Map, Queue) at its foundation? Java › Collections FrameworkJavaCollections FrameworkBeginner
2What is the difference between fail-fast and fail-safe iterators in the Collections Framework, and which collections use each? Java › Collections FrameworkJavaCollections FrameworkIntermediate
3How does the Collections Framework's fail-fast modCount mechanism actually work internally, and why is it described as "best-effort" rather than a strict guarantee? Java › Collections FrameworkJavaCollections FrameworkAdvanced
4What are the immutable collection factory methods (List.of(), Set.of(), Map.of()) introduced in Java 9, and how do they differ from Collections.unmodifiableList()? Java › Collections FrameworkJavaCollections FrameworkIntermediate
5What is the purpose of the Collections utility class's synchronization wrappers (Collections.synchronizedList(), etc.), and how do they differ from genuinely concurrent collections like ConcurrentHashMap? Java › Collections FrameworkJavaCollections FrameworkIntermediate
6What is the difference between the Iterable and Iterator interfaces, and how does the enhanced for-each loop rely on them? Java › Collections FrameworkJavaCollections FrameworkBeginner
7What are the key performance differences between ArrayList and LinkedList for common operations (random access, insertion/removal at various positions), and when would you choose one over the other? Java › Collections FrameworkJavaCollections FrameworkIntermediate
8What is the contract between equals() and hashCode() that a custom class must satisfy to work correctly as a HashMap key or HashSet element? Java › Collections FrameworkJavaCollections FrameworkIntermediate
9What is the purpose of the Deque interface, and how does it unify both stack (LIFO) and queue (FIFO) behavior in a single interface? Java › Collections FrameworkJavaCollections FrameworkIntermediate
10How does PriorityQueue work internally (as a binary heap), and what ordering does it use by default versus with a custom Comparator? Java › Collections FrameworkJavaCollections FrameworkIntermediate
11How does HashMap's internal implementation work (hashing, bucket array, treeification), and how did its collision-handling strategy change in Java 8? Java › Collections FrameworkJavaCollections FrameworkAdvanced
12How do you choose between HashMap, LinkedHashMap, and TreeMap based on their different ordering guarantees and performance characteristics? Java › Collections FrameworkJavaCollections FrameworkAdvanced
13How does TreeMap/TreeSet's red-black tree implementation guarantee O(log n) operations, and what role does the Comparable/Comparator interface play in maintaining sorted order? Java › Collections FrameworkJavaCollections FrameworkAdvanced
14How would you implement a custom Comparator with multiple sort criteria (e.g., sort by last name, then by first name as a tiebreaker) using the Comparator.comparing() and thenComparing() fluent API? Java › Collections FrameworkJavaCollections FrameworkAdvanced
15How would you choose the correct initial capacity for a HashMap to avoid unnecessary resizing overhead, given the relationship between capacity, load factor, and resize threshold? Java › Collections FrameworkJavaCollections FrameworkAdvanced
16How do you declare, initialize, and access elements of a one-dimensional array in Java? Java › Arrays & Multidimensional ArraysJavaArrays & Multidimensional ArraysBeginner
17How do you retrieve all constants of an enum type, and how would you iterate over them? Java › EnumsJavaEnumsBeginner
18What is the default behavior of equals() and hashCode() inherited from Object, and why is it usually necessary to override them for value-based classes? Java › equals(), hashCode() & toString() ContractsJavaequals(), hashCode() & toString() ContractsBeginner
19What is the recommended way to combine multiple field values into a single hashCode() implementation, following the common formula used by IDE-generated code? Java › equals(), hashCode() & toString() ContractsJavaequals(), hashCode() & toString() ContractsBeginner
20What does it mean for an object to be 'eligible for garbage collection' in terms of reachability from GC roots? Java › Garbage CollectionJavaGarbage CollectionBeginner
21What problem do generics solve compared to using raw types (like a pre-Java-5 List without a type parameter), and how do they improve compile-time type safety? Java › GenericsJavaGenericsBeginner
22What utility methods does java.util.Arrays provide for common array operations like sorting, searching, filling, and comparing? Java › Arrays & Multidimensional ArraysJavaArrays & Multidimensional ArraysIntermediate
23How do you convert between an array and a List (ArrayList) in both directions, and what pitfalls exist with Arrays.asList()? Java › Arrays & Multidimensional ArraysJavaArrays & Multidimensional ArraysIntermediate
24What is array covariance's relationship to generic arrays, and why can't you directly create a generic array like new T[10] or new List<String>[10]? Java › Arrays & Multidimensional ArraysJavaArrays & Multidimensional ArraysIntermediate
25How would you flatten a 2D array into a 1D array, and conversely, reshape a 1D array into a 2D array? Java › Arrays & Multidimensional ArraysJavaArrays & Multidimensional ArraysIntermediate
26How does the EnumSet and EnumMap provide more efficient alternatives to HashSet<Enum> and HashMap<Enum, V> specifically for enum keys? Java › EnumsJavaEnumsIntermediate
27What are the five formal properties an equals() implementation must satisfy according to its documented contract (reflexive, symmetric, transitive, consistent, and null-handling)? Java › equals(), hashCode() & toString() ContractsJavaequals(), hashCode() & toString() ContractsIntermediate
28How does Comparable's compareTo() method relate to equals(), and what does it mean for compareTo() to be 'consistent with equals'? Java › equals(), hashCode() & toString() ContractsJavaequals(), hashCode() & toString() ContractsIntermediate
29What is the difference between a Consumer<T> and a BiConsumer<T,U>, and how would you use BiConsumer for operations needing two inputs but no return value, such as Map.forEach()? Java › Functional Interfaces & Method ReferencesJavaFunctional Interfaces & Method ReferencesIntermediate
30What is an unbounded wildcard (List<?>), and when is it more appropriate to use than a bounded generic method with a type parameter <T>? Java › GenericsJavaGenericsIntermediate
31How would you implement a generic Stack<T> class from scratch, demonstrating how a self-contained generic data structure is typically structured? Java › GenericsJavaGenericsIntermediate
32What is a raw type in Java, and why does the compiler still permit using them (with an unchecked warning) despite generics having been available since Java 5? Java › GenericsJavaGenericsIntermediate
33What is the difference between the == operator and the .equals() method when comparing String objects, and why does String's string pool (interning) behavior sometimes make == appear to 'work' for strings? Java › Java Fundamentals: Syntax, Data Types & OperatorsJavaJava Fundamentals: Syntax, Data Types & OperatorsIntermediate
34What are generics in C#, and what specific problems do they solve compared to writing type-specific code? C# › GenericsC#GenericsIntermediate
35How would you implement a custom, resizable dynamic array (similar to ArrayList's internal mechanism) from scratch using a raw Java array, including the amortized doubling growth strategy? Java › Arrays & Multidimensional ArraysJavaArrays & Multidimensional ArraysAdvanced
36How would you implement a memory-efficient sparse matrix representation in Java when a large 2D array would mostly contain zero/default values, avoiding the memory waste of a full dense array? Java › Arrays & Multidimensional ArraysJavaArrays & Multidimensional ArraysAdvanced
37How would you implement a custom compareTo()-based ordering for an enum that differs from its natural declaration-order ordering, given Comparable's default implementation uses ordinal()? Java › EnumsJavaEnumsAdvanced
38Why must hashCode() be overridden whenever equals() is overridden, and what specific, hard-to-diagnose bugs occur in a HashMap when this contract is violated (equals() overridden but hashCode() left as default)? Java › equals(), hashCode() & toString() ContractsJavaequals(), hashCode() & toString() ContractsAdvanced
39How does Java Record's automatically-generated equals(), hashCode(), and toString() implementations work, and in what specific ways do they differ from a manually-written, field-by-field implementation? Java › equals(), hashCode() & toString() ContractsJavaequals(), hashCode() & toString() ContractsAdvanced
40How would you implement equals()/hashCode() correctly for a class containing a mutable field, and why does using such a class as a HashMap key or HashSet element create a serious risk? Java › equals(), hashCode() & toString() ContractsJavaequals(), hashCode() & toString() ContractsAdvanced
41How would you use BiFunction combined with Stream's reduce() to implement a custom aggregation, and how does this relate to the more general concept of a fold operation in functional programming? Java › Functional Interfaces & Method ReferencesJavaFunctional Interfaces & Method ReferencesAdvanced
42How do bounded wildcards (? extends T and ? super T) work, and what does the PECS (Producer Extends, Consumer Super) mnemonic mean for choosing between them? Java › GenericsJavaGenericsAdvanced
43How would you implement a generic class with multiple type parameters and bounded type parameters (like <T extends Comparable<T>>), and what does this specific bound enable? Java › GenericsJavaGenericsAdvanced
44How do generics interact with arrays, and why does the JDK itself sometimes use an unsafe cast (like in ArrayList's internal implementation) to work around the inability to create generic arrays directly? Java › GenericsJavaGenericsAdvanced
45How does variance (covariance, contravariance, invariance) apply differently to Java arrays versus Java generics, and what practical safety trade-off does this design difference represent? Java › GenericsJavaGenericsAdvanced
46How would you implement the classic Iterator design pattern using a private non-static inner class, letting the inner Iterator implementation access the outer collection's private internal state directly? Java › Inner Classes & Anonymous ClassesJavaInner Classes & Anonymous ClassesAdvanced