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

Is it possible to replace Hashtable with ConcurrentHashMap in Java?

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

Contents


More Related Answers

  • change the value in a hashtable java
  • Java Hashmap Replace Elements
  • java hashmap replace
  • Briefly explain concurrentHashMap. How is it better than HashMap and HashTable in terms of concurrency?

  • Is it possible to replace Hashtable with ConcurrentHashMap in Java?

    0

    Yes, a ConcurrentHashMap can be replaced with Hashtable in Java.

    But it requires careful observation, since locking behavior of

    Hashtable is different than that of ConcurrentHashmap.

    A Hashtable locks whole Map instead of a portion of Map.

    Compound operations like if(Hashtable.get(key) == null) put(key,

    value) work in Hashtable but not in ConcurrentHashMap.

    In a ConcurrentHashMap we use putIfAbsent() method for such a

    scenario.

    https://www.geeksforgeeks.org/difference-between-concurrenthashmap-hashtable-and-synchronized-map-in-java/

    Popularity 1/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.