title: Set vs List when need both unique elements and access by index
body: <p>I need to keep a unique list of elements seen and I also need to pick random one from them from time to time. There are two simple ways for me to do this.</p>
  
  <ol>
  <li><p>Keep elements seen in a Set - that gives me uniqueness of elements. When there is a need to pick random one, do the following:</p>
  
  <pre><code>elementsSeen.toArray()[random.nextInt(elementsSeen.size())]
  </code></pre></li>
  <li><p>Keep elements seen in a List - this way no need to convert to array as there is the get() function for when I need to ask for a random one. But here I would need to do this when adding.</p>
  
  <pre><code>if (elementsSeen.indexOf(element)==-1) {elementsSeen.add(element);}
  </code></pre></li>
  </ol>
  
  <p>So my question is which way would be more efficient? Is converting to array more consuming or is indexOf worse? What if attempting to add an element is done 10 or 100 or 1000 times more often?</p>
  
  <p>I am interested in how to combine functionality of a list (access by index) with that of a set (unique adding) in the most performance effective way. </p>