title: Accessing elements in a treeset
body: <p>I am attempting some very basic java here and have reached a bit of a head scratcher.  Essentially,I need to read some element from a file into some type of array or list, sort them, eliminate duplicates, and then return the first three elements.  TreeSet  seemed like the perfect fit in so much as it does the sort and kills the duplicates.  My issue is that I am confounded as to how to return only the first three elements.  The iterator seems to run all the way through the set.  Creating a while loop with a manual iterator to contain a while loop that holds the iterator loops seems confusing and unlikely to be successful.  Is the answer here that I need to iterate through the treeset and place each element into an arraylist so that I can then access the first three elements?  I mean, it seems that this would work but it seems highly convoluted.  Tips?</p>