Flashcards

Quick study sessions to strengthen memory and retain key concepts.

Flashcard Study

Java: Set Interface and HashSet

Front

How do you remove all elements from a HashSet?

Use the clear() method to remove all elements from a HashSet. The clear() method removes all elements from…

View Card →
Flashcard Study

Java: Set Interface and HashSet

Front

What happens if mutable objects are used in a HashSet?

Changing a mutable object's state can corrupt HashSet behavior. If an object's fields used in hashCode() or equals()…

View Card →
Flashcard Study

Java: Set Interface and HashSet

Front

What impact does a poor hash function have on HashSet?

A poor hash function causes more collisions, degrading performance to O(n). If a hash function distributes elements unevenly,…

View Card →
Flashcard Study

Java: Set Interface and HashSet

Front

Explain the performance benefit of using HashSet for membership checks?

HashSet provides average O(1) time complexity for membership checks. HashSet achieves constant time complexity for lookups by using…

View Card →
Flashcard Study

Java: Set Interface and HashSet

Front

When is a Set preferable to a List?

Use a Set when you need unique elements and don't care about order. A Set is ideal for…

View Card →
Flashcard Study

Java: Set Interface and HashSet

Front

Why might a HashSet not prevent duplicates with custom objects?

If hashCode() and equals() are not correctly overridden, duplicates can occur. For custom objects, you must override hashCode()…

View Card →
Flashcard Study

Java: Set Interface and HashSet

Front

How does HashSet check for duplicates?

HashSet uses hashCode() and equals() methods to check for duplicates. When you add an object to a HashSet,…

View Card →
Flashcard Study

Java: Set Interface and HashSet

Front

Why does a Set in Java collections matter in this design?

A Set ensures that all elements are unique, with no duplicates. The Set interface provides a collection that…

View Card →
Flashcard Study

Java: Set Interface and HashSet

Front

When is `HashSet` the right model?

When uniqueness or repeated membership checks matter more than ordering. A set communicates that duplicates are not meaningful.…

View Card →
Flashcard Study

Java: Queue and Deque Basics

Front

What are the design implications of using a Deque in a multi-threaded application?

Deques are not thread-safe by default. Frame the concept in practical terms so you can explain it during…

View Card →