The three types of collections extending Collections interface are
- List - anything, in the order of addition
- Set- no duplicates
- Queue- peep and pop operations
Set
This collection does not accept duplicate objects.
HashSet
HashSet is backed by HashMap, which implies that there is no preservation of insertion order. Also since the inserted elements are not sorted, just remember that this could allow null element as well.
TreeSet
Inserted elements are sorted based on the supplied Comparator or natural ordering. This is backed by TreeMap which cannot take null as key.
No comments:
Post a Comment