KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Why does the java.util.Set interface lack get(int Index) , or any similar get() method? It seems that sets are great for putting things into, but I can't find an elegant way of retrieving a single item from them. If I know I want the first item, I can use set.iterator().next() , but otherwise it seems I have to cast to an Array to retrieve an item at a specific index? What are the appropriate ways of retrieving data from a set? (other than using an iterator) I'm asking this question because I had a dbUnit test, where I could reasonably assert that the returned set from a query had only 1 item, and I was trying to access that item. So, what's the difference between Set and List ?
Tags (comma-separated)
Save Edits
Cancel