Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out

How can we synchronize the elements of a List, a Set or a Map?

Pragya Keshap answered on February 4, 2023 Popularity 3/10 Helpfulness 1/10

Contents


More Related Answers


How can we synchronize the elements of a List, a Set or a Map?

0

Sometimes we need to make collections Thread-safe for use in

Multi-threading environment. In Java, Collections class provides

useful static methods to make a List, Set or Map as synchronized

collections. Some of these methods are:

static Collection synchronizedCollection(Collection

c)

Returns a synchronized (thread-safe) collection backed by the

specified collection.

static List synchronizedList(List list)

Returns a synchronized (thread-safe) list backed by the specified

list.

static MapsynchronizedMap(Map m)

Returns a synchronized (thread-safe) map backed by the specified

map.

static Set synchronizedSet(Set s)

Returns a synchronized (thread-safe) set backed by the specified

set.

static

SortedMap synchronizedSortedMap(SortedMap m)

Returns a synchronized (thread-safe) sorted map backed by the

specified sorted map.

static SortedSet synchronizedSortedSet(SortedSet s)

Returns a synchronized (thread-safe) sorted set backed by the

specified sorted set

https://javaconceptoftheday.com/synchronize-arraylist-hashset-and-hashmap-in-java/

Popularity 3/10 Helpfulness 1/10 Language java
Source: Grepper
Link to this answer
Share Copy Link
Contributed on Feb 04 2023
Pragya Keshap
0 Answers  Avg Quality 2/10


X

Continue with Google

By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
X
Grepper Account Login Required

Oops, You will need to install Grepper and log-in to perform this action.