Collection Basics
What is Collection
Why Collection ?
Collection API
Collection Hierarchy
List
What is List
What is ArrayList
What is LinkedList
What is Vector
method of vector class in java
What is Stack
List Advance
ArrayList user defined object
ArrayList internal implementation
LinkedList internal implementation
ArrayList VS LinkedList
ArrayList VS Vector
Set
What is HashSet
What is LinkedHashSet
What is TreeSet
Set Advance
When to Use HashSet
HashSet internal Working
When to use LinkedHashSet
TreeSet internal Working
Set add method
Iterate Collection
Iterate Collection
Advance for loop
What is Iterator
Advantage of Iterator
What is ListIterator
Iterator VS ListLterator
What is Enumeration
Enumeration VS Iterator
Map
What is HashMap
What is LinkedHashMap
What is TreeMap
What is Hashtable
What is WeakHashMap
What is IdentityHashMap
What is Properties file
Map Advance
What is Load-Factor
how to load properties file in java
how to iterate map in java
how to retrieve element of map using keySet
difference between hashmap and hashtable
Map Interview
Internal implementation of HashMap
HashMap Collision
Rehashing Process
Internal working of LinkedHashMap
Queue
What is Priority Queue
Concurrent Collections
Concurrent Collections
Concurrentmap in java
Why ConcurrentModificationException
What is ConcurrentHashMap
Internal Implementation of CHM
HashMap VS ConcurrentHashMap
What is CopyOnWriteArrayList
What is CopyOnWriteArraySet
Concurrent Map 2
Arraylist VS CopyOnWriteArrayList
put() VS putIfAbsent()
remove() method
replace() method
Collection Sorting
Comparable
Comparator
Comparable VS Comparator
Sort by multiple fields
Extra
Legacy class
Arrays class
What is Collections
Collection VS Collections
immutable object

what is hashmap in java


What is HashMap in java

HashMap is one of the implementation class of Map interface which is use to store element in the form of key-value pairs.

HashMap must have unique key but value can be duplicate in HashMap, means HashMap does not allow duplicate key.

Points to Remember

  1. HashMap may have one null key and multiple null values.
  2. HashMap uses Hashtable internally to store elements.
  3. HashMap does not maintain order of element
  4. HashMap is not synchronized by default

Methods of HashMap

  1. put(key,value)   :   Use to store key and value to HashMap.
  2. get(Object key)  :   Use to get element from HashMap.
  3. remove(Object o)   :    Use to remove element from HashMap
  4. void clear()             :    Use to clear all element from HashMap.
  5. int size()      :   Use to get how many element in HashMap.

How does object store in HashMap

HashMap use to store objects in Key-Value pairs.

hashmap-key-value-pair

Example

import java.util.*;
class HashMapTest 
{
 public static void main(String[] args) 
 {
    HashMap<String,Integer> ht=new HashMap<>();
    ht.put("a",101);
    ht.put("b",102);
    ht.put("c",103);
    for(Map.Entry<String,Integer> m  :  ht.entrySet()){
      System.out.println(m.getKey()+" "+m.getValue()); 
    }
 }
}

Output

a 101
b 102
c 103






Full-stack web and mobile app development company Contact Us : Skype: indore.webcoder Email: info@w3sparks.com Sales: +91 8085506229