Home » Java Collections synchronizedSet() Method with Examples

Java Collections synchronizedSet() Method with Examples

by Online Tutorials Library

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

Test it Now

Output:

Synchronized set is :[Twitter, Instagram, Facebook, Whatsapp]  

Example 2

Test it Now

Output:

Set before Synchronized set: [101, 102, 103, 104, 105]  Set after Synchronized set-  101  102  103  104  105  

Example 3

Test it Now

Output:

initial set size: 0  1000  

You may also like