Enrol to start learning
Reading is open to everyone. Enrolling is free, and it is what unlocks the audio lessons, practice tests and progress tracking.
15.3.1. Set Interface
This section
Practice test
11 questions on this section. Wrong answers show you what to read again.
Sign up to take itWhole chapter
Revision test
Mixed questions from across the chapter. Your answers get marked.
Sign up to take itQuick
Flashcard drill
4 cards from this lesson. Good the night before a test.
Try these first
- 1.
What does the Set Interface prevent in a collection?
Hint
Consider the unique nature of elements.
- 2.
What implementation of Set maintains the order of insertion?
Hint
Think about how elements are added.
- 3.
What does the Set interface guarantee?
- Allows duplicates
- Does not allow duplicates
- Stores elements in order
Hint
Think about what makes a Set different from a List.
- 4.
True or False: A LinkedHashSet preserves the insertion order.
- True
- False
Hint
Recall how elements are organized.
- 5.
You are building a contact application that must ensure that no duplicate emails exist. Which Set implementation would you choose and why?
Hint
Think about access speed versus order preservation.
- 6.
Write a Java method that accepts a List of integers and returns a Set containing only the unique integers.
Hint
Play with the HashSet constructor that takes a collection.
Exercises
Total Questions
2
Estimated Time
4 min
Passing Score
70%
Instructions
- Read each question carefully
- You can use hints if you need help
- Complete all questions before submitting
4 more questions available
Enrol freeQuiz
Total Questions
2
Estimated Time
4 min
Passing Score
70%
Instructions
- Read each question carefully
- You can use hints if you need help
- Complete all questions before submitting
1 more question available
Enrol freeChallenge Problems
Total Questions
2
Estimated Time
4 min
Passing Score
70%
Instructions
- Read each question carefully
- You can use hints if you need help
- Complete all questions before submitting