Flashcards

Quick study sessions to strengthen memory and retain key concepts.

Flashcard Study

Java: Iteration and Traversal

Front

Why might an Iterator be preferred for safe removal during iteration?

It allows safe removal of elements without causing ConcurrentModificationException. Using an Iterator to remove elements during iteration prevents…

View Card →
Flashcard Study

Java: Iteration and Traversal

Front

How would you explain an enhanced for loop in a Java interview?

A simplified iteration construct for collections and arrays. The enhanced for loop, introduced in Java 5, allows straightforward…

View Card →
Flashcard Study

Java: Iteration and Traversal

Front

When do you need an `Iterator` instead of only an enhanced for-loop?

When you must remove elements safely during traversal. Enhanced for-loops are great for simple reads, but iterators matter…

View Card →
Flashcard Study

Java: equals and hashCode in Collections

Front

Why do `HashSet` and `HashMap` care about `equals` and `hashCode`?

They use those methods to decide sameness and where items belong internally. Hash-based collections do not know your…

View Card →
Flashcard Study

Java: Collection Performance Basics

Front

Reading and understanding Java Collections code?

Focus on collection type, operations, and intended use. When reading Java Collections code, identify the type of collection…

View Card →
Flashcard Study

Java: Collection Performance Basics

Front

Designing collections for catalogs?

Choose based on operation needs and element characteristics. Designing collections requires understanding operation needs (e.g., frequent updates, reads)…

View Card →
Flashcard Study

Java: Collection Performance Basics

Front

HashSet vs. ArrayList performance?

HashSet offers unique, faster lookups; ArrayList allows duplicates and ordering. HashSet is optimized for scenarios requiring unique elements…

View Card →
Flashcard Study

Java: Collection Performance Basics

Front

Benefits of using HashMap?

HashMap offers fast, constant time operations. HashMap's strength is its ability to perform operations like put, get, and…

View Card →
Flashcard Study

Java: Collection Performance Basics

Front

Common pitfalls with ArrayList?

Misusing its dynamic sizing can lead to inefficiency. While ArrayList automatically resizes, frequent resizing can cause performance issues.…

View Card →
Flashcard Study

Java: Collection Performance Basics

Front

Choosing between HashSet and TreeSet?

HashSet is faster, TreeSet maintains order. HashSet offers faster operations (average O(1)) because it uses hashing, while TreeSet…

View Card →