title: Collections.newSetFromMap(»ConcurrentHashMap«) vs. Collections.synchronizedSet(»HashSet«)
body: <p>Apparently, there are two ways to obtain a <a href="https://en.wikipedia.org/wiki/Thread_safety" rel="nofollow noreferrer">thread-safe</a> <a href="https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/HashSet.html" rel="nofollow noreferrer">HashSet</a> instance using Java’s <a href="https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/Collections.html" rel="nofollow noreferrer"><code>Collections</code></a> utility class.</p>
  <ul>
  <li><a href="https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/Collections.html#newSetFromMap(java.util.Map)" rel="nofollow noreferrer">Collections.newSetFromMap</a>( <a href="https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/concurrent/ConcurrentHashMap.html" rel="nofollow noreferrer">ConcurrentHashMap</a> )</li>
  <li><a href="https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/Collections.html#synchronizedSet(java.util.Set)" rel="nofollow noreferrer">Collections.synchronizedSet</a>( <a href="https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/HashSet.html" rel="nofollow noreferrer">HashSet</a> )</li>
  </ul>
  <p>I ask:</p>
  <ul>
  <li>How do they differ?</li>
  <li>Which, and under what circumstances, is to be preferred over the other?</li>
  </ul>