Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6789593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:37:22+00:00 2026-05-26T17:37:22+00:00

I know what Sets are and common operations on sets like union, intersection, difference,

  • 0

I know what Sets are and common operations on sets like union, intersection, difference, subset. However i don’t understand in which situations are set based operations desired? Any real world examples? What are the advantages of using set vs using a list or a Hash? If i have two lists then i can find the union,intersection of those lists too. So why use Sets?

Edit
I specifically want to know real world situations where i should use a set instead of a list.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T17:37:23+00:00Added an answer on May 26, 2026 at 5:37 pm

    Set guarantees there there is no duplicate object in it. List doesn’t so you can have multiple entries of “equal” objects in a list. There are million of things that you can use set and it will make your life much easier, for example, a set of countries, a set of username, etc. If you use a list to store these data, you will need to check whether your list has already contained the same element or not before adding the new one unless the list is allowed to have duplicates.

    In other words, set may be considered as a list without any duplicates. However, the interface of Set and List aren’t really the same in Java. For example, you aren’t able to get the element at certain position in a set. This is because position is not important in the set (but it is for a list). Therefore, selecting which data collection to use depends entirely on the purpose.

    I, myself, found that Set is very useful in many cases and reduces the amount of checking for duplicates. One of my use cases is to use set to find how many chemical elements are in a molecule. The molecule contains a list of atom objects and each atom is associated to a element symbol so in order to find the type of element, I loop over all the atoms and add the element to an element set. All the duplicates are removed without hassle.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know which property sets the text color for disabled control? I have
Ok so my admin sets to edit a book which was created. I know
I would like to know the best approach to create a Common Information Model
I know that I can do something like $int = (int)99; //(int) has a
I would like to perform an Except operation on set of items. Code is
a) Do fonts know anything about coded character sets (Unicode, ASCII, etc.)? In other
I know it can be convenient for a programmer to group different sets of
I know it is relatively easy to compute the sets of k-nearest neighbours from
I know that Reflection can be expensive. I have a class that gets/sets to
Say I create two sets of tuples like so: Dim losSPResults As List(Of spGetDataResults)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.