![]() The synchronized collections classes, Hashtable and Vector, and the synchronized wrapper classes, Collections.synchronizedMap and Collections.synchronizedList, provide a basic conditionally thread-safe implementation of Map and List. HashMap can be synchronized by calling Collections.getSynchronizedMap(hashmap) Ĥ – Why we need ConcurrentHashMap and CopyOnWriteArrayList ?.So, when get() is called, the hashcode() would point to the bucket location, then the use key.equals() to find the correct node in the linked list.Inside the bucket, data is stored in linked list, so in collision scenario, it will get added to next node.If two key objects have same hashcode, bucket location will be the same and collision occurs in hashmap.when get() is called, the hashcode() on key is used to identify the bucket location and the value if returned. ![]() when put() is called, hashmap implementation calls hashcode() on the key to identify the bucket location… then stores both key+value in the bucket.it has a number of buckets which stores key-value pairs.put() and get() methods are used to store and retrieve data from hashmap.HashMap works on the principle of hashing.Fail-fast means if one thread is iterating over a map and another is trying to modify it by adding/deleting elements, it will throw ConcurrentModificationException. Hashtable does not allow null key, hashmap allows 1 null key & several null values. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |