Core JAVA
Java Development KIT (JDK)
Java Runtime Environment (JRE)
Java Virtual Machine (JVM)
Java overview
Java basics
Java Objects and classes
Java Constructors
Java basic datatypes
Java variable types
Java modifiers/Access Modifiers In Java
Java Basic Operators
Java Loops and Controls
Java conditions
Java numbers and characters
Java strings
Java arrays
Java date time
Java methods
Java file and IO operations
Java exceptions
Inner class
Java OOPs Concepts
Java Inheritance
Java Polymorphism
Java Abstraction
Java Encapsulation
Java Interface
Cohesion and Coupling
Association, Aggregation and Composition
Java Collections
Java ArrayList
Java LinkedList
Set and HashSet
LinkedHashSet and TreeSet
Queue and PriorityQueue
Deque and PriorityQueue
Java Map Interface
Java HashMap
Internal Working Of Java HashMap
Java Mutithread
Methods of Thread In Java
Join , run & Start Method in Threads
Difference b/w start & run Methods in Threads
Java Concurrency Package & its Features
CountDownLatch, CyclicBarrier, Semaphore and Mutex in Thread
Java Runtime Environment (JRE)
Java Virtual Machine (JVM)
Java overview
Java basics
Java Objects and classes
Java Constructors
Java basic datatypes
Java variable types
Java modifiers/Access Modifiers In Java
Java Basic Operators
Java Loops and Controls
Java conditions
Java numbers and characters
Java strings
Java arrays
Java date time
Java methods
Java file and IO operations
Java exceptions
Inner class
Java OOPs Concepts
Java Inheritance
Java Polymorphism
Java Abstraction
Java Encapsulation
Java Interface
Cohesion and Coupling
Association, Aggregation and Composition
Java Collections
Java ArrayList
Java LinkedList
Set and HashSet
LinkedHashSet and TreeSet
Queue and PriorityQueue
Deque and PriorityQueue
Java Map Interface
Java HashMap
Internal Working Of Java HashMap
Java Mutithread
Methods of Thread In Java
Join , run & Start Method in Threads
Difference b/w start & run Methods in Threads
Java Concurrency Package & its Features
CountDownLatch, CyclicBarrier, Semaphore and Mutex in Thread
Java HashMap
Java HashMap<K, V> implements Map interface, it represents Map data structure, each element in the map is a key, value pair.
- HashMap keys are always unique.
- HashMap is not thread safe.
- A key will always correspond to a single value.
- Key should be immutable.
- HashMap uses hashing algorithms to uniquely store and find data.
- HashMap is similar to HashTable but it is not synchronized safe on other had HashTable is synchronized(thread safe).
- Default initalCapacity of hashMap is 16 and load factor is 0.75.
HashMap Constructors
HashMap has below 4 types of constructors:
1. HashMap() – This constructor has no parameters.
Example:
HashMap myMap = new HashMap();
2.HashMap(int initialCapacity) – HashMap with initial capacity parameter.
Example:
HashMap myMapWithCap = new HashMap(12);
3. HashMap(int initialCapacity, float loadFactor) – HashMap with initial capacity and load factor.
Example:
HashMap myMapWithCapAndLoadFactor = new HashMap(12, .75F);
4. HashMap(Map map) – HashMap which takes another map as parameter.
Example:
HashMap myMap = new HashMap();
HashMap mapWhichTakesAnotherMap = new HashMap(myMap);
HashMap Example Non Generic
In a non-generic or old way, we don’t specify the data type of key and value.
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
public class MapExamples {
public static void main(String[] args) {
   HashMap myMap = new HashMap();
   myMap.put("101", "Tom");
   myMap.put("102", "Rom");
   myMap.put("103", "Jonny");
   myMap.get("101");
   Set eSet= myMap.entrySet();
   Iterator itr = eSet.iterator();
   while(itr.hasNext()) {
    Map.Entry entry = (Map.Entry)itr.next();
       System.out.println("Key:"+entry.getKey()+" value:"+entry.getValue());
   }
}
}
Output
Key:101 value:Tom
Key:102 value:Rom
Key:103 value:Jonny
HashMap Example Generic
In the generic map we specify the data type of key and value pair.
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
public class MapExamples {
public static void main(String[] args) {
   HashMap <String, String> myMap = new HashMap<String, String>();
   myMap.put("101", "Tom");
   myMap.put("102", "Rom");
   myMap.put("103", "Jonny");
   myMap.get("101");
    Set eSet= myMap.entrySet();
   Iterator itr = eSet.iterator();
   while(itr.hasNext()) {
       Map.Entry entry = (Map.Entry)itr.next();
       System.out.println("Key:"+entry.getKey()+" value:"+entry.getValue());
   }
}
}
Output
Key:101 value:Tom
Key:102 value:Rom
Key:103 value:Jonny
HashMap Add, Remove and Iterate Operations
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
public class HashMapExamples {
public static void main(String[] args) {
   HashMap<String, String> myMap = new HashMap<String, String>();
   myMap.put("101", "Tom"); //Adds element in map
   myMap.put("102", "Rom");
    myMap.put("103", "Jonny");
   //Get a value for given key
   String getValue = myMap.get("101");
   //Remove
   myMap.remove("103");
   Set eSet = myMap.entrySet();
    Iterator itr = eSet.iterator();
   while (itr.hasNext()) {
       Map.Entry entry = (Map.Entry) itr.next();
       System.out.println("Key:" + entry.getKey() + " value:" + entry.getValue());
   }
}
}
Output
Key:101 value:Tom
Key:102 value:Rom