HashMap

HashMap

key(키)를 해싱하여 value(값)에 매핑할 수 있는 구조로 이루어진 자료구조이다.

Constructor

new HashMap()

Author:
  • ljsoo0925@gmail.com
Example
var hm = new HashMap ();

Methods

(static) clear()

This method is used to remove all of th mappings from this hash map.
Example
var hm = new HashMap ();
hm.put("A", 1);  
hm.put("B", 2); 
hm.clear(); 

(static) containsKey(key) → {Boolean}

This method is used to check if this hash map contains the specified key.
Example
var hm = new HashMap ();
var ret1 = hm.containsKey("A"); // ret1 = false
hm.put("A", 1);  
var ret2 = hm.containsKey("A"); // ret1 = true
Parameters:
Name Type Description
key undefined The key with which the specified value is to be associated.
Throws:
This method returns 'false' if the parameter is missing.
Returns:
This method returns ‘true’ if this hash map contains the specified key, or ‘false’ if this hash map doesn’t contain the specified key.
Type
Boolean

(static) containsValue(value) → {Boolean}

This method is used to check if this hash map contains the specified value.
Example
var hm = new HashMap ();
var ret1 = hm.containsValue(1); // ret1 = false
hm.put("A", 1);  
var ret2 = hm.containsValue(1); // ret1 = true
Parameters:
Name Type Description
value undefined The value with which the specified key is to be associated.
Throws:
This method returns 'false' if the parameter is missing.
Returns:
This method returns ‘true’ if this hash map contains the specified value, or ‘false’ if this hash map doesn’t contain the specified value.
Type
Boolean

(static) entrySet() → {Set}

This method is used to get a Set of the mappings in this hash map.
Example
var hm = new HashMap ();
hm.put("A", 1);  
hm.put("B", 2); 
hm.put("가", 2);
Set set = hm.keySet(); // set = {"A-1", "B-2", "가-2"}
Returns:
This method returns a set of the mappings in this hash map.
Type
Set

(static) get(key) → {undefined}

This method is used to get the value which mapped with the specified key from this hash map.
Example
var hm = new HashMap ();
hm.put("A", 1) ;
var ret = hm.get("A"); // ret1 = 1
Parameters:
Name Type Description
key undefined the key with which the specified value is to be associated.
Throws:
This method return false if the parameter is missing, or null if this hash map doesn’t contain this key.
Returns:
This method returns the value which be associated with the specified key.
Type
undefined

(static) isEmpty() → {Boolean}

This method is used to check if this hash map is empty.
Example
var hm = new HashMap ();
var ret1 = hm.isEmpty(); // ret1 = true;
hm.put("A", 1);  
hm.put("B", 2); 
var ret2 = hm.isEmpty(); // ret2 = false
Returns:
The method returns ‘true’ if this deque is empty, or ‘false’ if this deque is not empty.
Type
Boolean

(static) keySet() → {Set}

This method is used to get a Set of the keys in this hash map.
Example
var hm = new HashMap ();
hm.put("A", 1);  
hm.put("B", 2); 
hm.put("가", 2);
Set set = hm.keySet(); // set = {"A", "B", "가"}
Returns:
This method returns a set of the key in this hash map.
Type
Set

(static) put(key, value)

This method is used to insert the specified key with the specified value in this hash map.
Example
var hm = new HashMap ();
hm.put("A", 1);   // (key : A) - (Value : 1)
hm.put("가", 1);  // (key : 가) - (Value : 1)
hm.put("A", 2);   // (key : A) - (Value : 2) => change value associated with key A
Parameters:
Name Type Description
key undefined The key with which the specified value is to be associated.
value undefined The value to be associated with the specified key.
Throws:
This method returns 'false' if the either one parameter is missing.

(static) remove(key)

This method is used to remove the mapping with the specified key from this hash map.
Example
var hm = new HashMap ();
hm.put("A", 1);  
hm.put("B", 2); 
hm.remove("A"); // (key : A) - (Value : 1) will be removed
Parameters:
Name Type Description
key undefined the key with which the specified value is to be associated.
Throws:
This method returns 'false' if the parameter is missing, or null if this hash map doesn’t contain this key.

(static) size() → {Number}

This method is used to get the number of key-value mappings in this hash map.
Example
var hm = new HashMap ();
hm.put("A", 1);  
hm.put("B", 2); 
var size = hm.size(); // size = 2
Returns:
The method returns the number of values in this deque.
Type
Number