96
Java Collections synchronizedSet() Method
The synchronizedSet() method of Java Collections class is used to get a synchronized (thread-safe) set backed by the specified set.
Syntax
Following is the declaration of synchronizedSet() method:
Parameter
Parameter | Description | Required/Optional |
---|---|---|
s | It is the set which will be wrapped in a synchronized set. | Required |
Returns
The synchronizedSet() method returns a synchronized view of the specified Set.
Exceptions
NA
Example 1
Output:
Synchronized set is :[Twitter, Instagram, Facebook, Whatsapp]
Example 2
Output:
Set before Synchronized set: [101, 102, 103, 104, 105] Set after Synchronized set- 101 102 103 104 105
Example 3
Output:
initial set size: 0 1000
Next TopicJava Collections Class