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

  • SEARCH
  • Home
  • 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 8188969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:05:30+00:00 2026-06-07T03:05:30+00:00

Apparently, there are two ways to obtain a thread-safe HashSet instance using Java’s Collections

  • 0

Apparently, there are two ways to obtain a thread-safe HashSet instance using Java’s Collections utility class.

  • Collections.newSetFromMap( ConcurrentHashMap )
  • Collections.synchronizedSet( HashSet )

I ask:

  • How do they differ?
  • Which, and under what circumstances, is to be preferred over the other?
  • 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-06-07T03:05:32+00:00Added an answer on June 7, 2026 at 3:05 am

    What you may be thinking of is

    Set<Type> set = Collections.newSetFromMap(new ConcurrentHashMap<Type, Boolean>());
    

    This supports concurrent updates and reads. Its Iterator won’t throw ConcurrentModicationException. where as

    Set<Type> set = Collections.synchronizedSet(new HashSet<Type());
    

    Is more light weight but only allows one thread at a time to access the set. You need to lock the set explicitly if you want to Iterator over it and you can still get a CME if you don’t update it in a safe way (while iterating over it)

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

Sidebar

Related Questions

As far as I can see there are two ways, both with their drawbacks.
I've run across two very similar questions but the answers there apparently don't apply
I am working on a legacy framework and apparently there are two libraries, which
Apparently there is a database postgres that is created by default on each postgresql
I read that SHA-1 is being retired from the FIPS 180-2 standard. Apparently there
I've done some research and found that there apparently is an easy and understandable
Apparently, there's been a big brouhaha over whether or not Python needs tail-call optimization
There are many similar questions, but apparently no perfect match, that's why I'm asking.
I realize there are a few other questions about why Cygwin is apparently slow,
Apparently Java only plays .au audio files and I want to play mp3 files.

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.