Here is how this works. Set is an interface that extends the Collections object. HashSet is an instance of "Set". You can't just instantiate the interface. You do this with the concrete HashSet, TreeSet or LinkedHashSet implementations. Each of these handle the Collection differently.
The HashSet doesn't care what sequence the data is in, but will ensure no duplicates are allowed.
The TreeSet will sort the data and keep it in that order and the LinkedHashSet will retain the sortation that it originally was stored in.
Pretty simple eh.
No comments:
Post a Comment