java.util.Set

Set is another important Datastructure created in Java, just like List.
Set is same as List, except it dont contain duplicates, and dont maintain order.

As you remember, List can have duplicates & also maintains internal Order.

Set Types:

Below are the most used implementation classes of Set Interface.

  • HashSet – HashTable implementation of Set Interface.
  • TreeSet – Tree Implementation of Set Interface.

Simple Example of Set (using HashSet).,

Result:

[2019, 2018, 2017, 2016]

Leave a Reply

Your email address will not be published. Required fields are marked *