In “How HashMap works in Java“, we learned the internals of HashMap or ConcurrentHashMap class and how they fit into the whole concept. But when the interviewer asks you about HashMap related concepts, he does not stop only on the core concept. The discussion usually goes in multiple d...
In this tutorial, we’ll explore the concept of a shallow vsdeep copyof aHashMapalong with several techniques to copy aHashMapin Java. We’ll also consider some of the external libraries that can help us in specific cases. 2. Shallow vs Deep Copies Firstly, let’s understand the concept...
If we try to modify the collection while iterating over it, we getConcurrentModificationException. Java 1.5 introduced Concurrent classes in thejava.util.concurrentpackage to overcome this scenario. ConcurrentHashMap is the Map implementation that allows us to modify the Map while iteration. The Conc...
Most common interview questions are “How HashMap works in java”, “How get and put method of HashMap work internally”. Here I am trying to explain internal functionality with an easy example. Rather than going through theory, we will start with example first, so that you will get better...
In my previous post related to “How HashMap works in java“, I explained the internals of HashMap class and how they fit into whole concept. But when interviewer ask you about HashMap related concepts, he does not stop only on core concept. The discussion usually goes in multiple directio...
Most common interview questions are “How HashMap works in java”, “How get and put method of HashMap work internally”. Here I am trying to explain internal functionality with an easy example. Rather than going through theory, we will start with example first, so that you will get better...
importjava.util.HashMap;importjava.util.Map;publicclassMapExample{publicstaticvoidmain(String[]args){Map<String,Integer>nameAgeMap=newHashMap<>();nameAgeMap.put("Eric",20);nameAgeMap.put("John",21);nameAgeMap.put("LiLei",19);nameAgeMap.put("Wang",28);nameAgeMap.put("Zhang",24);Syst...
In Java, object references can be of many types. Let’s discuss them before digging further into the concept of weak keys inWeakHashMap. 3.1. Strong References, Soft References and Weak References Strong referencesare the references we create in a normal program. These are simple variable assig...
In this article, we explored the concept of hashmaps and demonstrated how to implement a hashmap using jQuery. We discussed the benefits of using a hashmap and highlighted some common use cases. By leveraging the power of jQuery and hashmaps, developers can improve the efficiency and performa...
Java - Lambdas and putIfAbsent, The computeIfAbsent method as described below has indeed been added to Java SE 8. The semantics appear to be very close to the pre-release version. In addition, computeIfAbsent, along with a whole pile of new default methods, has been added to the Map int...