I'm learning Java.util.Collection and have encountered the following question and answer.
Consider the four core interfaces, Set, List, Queue, and Map. For each of the following four assignments, specify which of the four core interfaces is best-suited, and explain how to use it to implement the assignment.
1) Whimsical Toys Inc (WTI) needs to record the names of all its employees. Every month, an employee will be chosen at random from these records to receive a free toy.
The answer provided by the tutorial is
Use a List. Choose a random employee by picking a number between 0 and size()-1.
But I was just wondering shouldn't Set
be used instead of List
? Cause employees are unique individuals and we dont want the same employee to be entered multiple times. Is my thinking correct or am I missing something? Does anyone have any suggestions? Thanks in advance for any help!