Wednesday, Oct 17th

Last update12:59:40 PM GMT

Set

Write e-mail

A set interface is part of Java collection framework, which cares about uniqueness. That is, it doesn’t allow duplicates. The equals method in the Object class makes sure that identical objects don’t exist in set. There are various implementations of the Set interface, as stated below:

argaiv1608

  • HashSet :
    • No guarantee of element order. It doesn’t maintain insertion order, and doesn’t support sorted order.
    • Implementation based on Hash Table.
  • LinkedHashSet
    • Keeps the elements in the same order as they are inserted.
    • Implementation based on Hash Table and doubly-linked list.
  • TreeSet
    • It keeps the elements in the sorted order. So, if we insert elements of type String or any wrapper class, sorted order is itself maintained. But if we want user defined class objects to be in sorted order, comparator or comparable object need to be provided to the set.
    • Implementation based on Balanced Tree.

Share this post



Add comment

Please refrain from using slang or abusive language in the comments.
To avoid waiting for your comment to be published after being reviewed, please log in as a registered user.


Security code
Refresh

Web Hosting