ConcurrentHashSet

Introduction

We know that the JDK provides a thread-safe version of HashMap: ConcurrentHashMap, but there is no corresponding ConcurrentHashSet. Hutool has leveraged ConcurrentHashMap to encapsulate a thread-safe ConcurrentHashSet.

Usage

The usage is consistent with ordinary HashSet:

Set<String> set = new ConcurrentHashSet<>();
set.add("a");
set.add("b");