import
java.util.Collection;
import
java.util.HashMap;
import
java.util.Iterator;
import
java.util.Map;
import
java.util.Map.Entry;
import
java.util.Set;
public
class
HashMapImplementation<K, V> {
private
HashMap<K, V> hashMap;
public
HashMapImplementation()
{
hashMap =
new
HashMap<K, V>();
}
public
HashMapImplementation(
int
initialCapacity)
{
hashMap =
new
HashMap<K, V>(initialCapacity);
}
public
HashMapImplementation(
int
initialCapacity,
float
loadFactor)
{
hashMap =
new
HashMap<K, V>(initialCapacity,
loadFactor);
}
public
HashMapImplementation(Map<?
extends
K, ?
extends
V> m)
{
hashMap =
new
HashMap<K, V>(m);
}
public
void
clear() { hashMap.clear(); }
public
Object clone() {
return
hashMap.clone(); }
public
boolean
containsKey(Object key)
{
return
hashMap.containsKey(key);
}
public
boolean
containsValue(Object value)
{
return
hashMap.containsValue(value);
}
public
Set<Map.Entry<K, V> > entrySet()
{
return
hashMap.entrySet();
}
public
V get(Object key) {
return
hashMap.get(key); }
public
boolean
isEmpty() {
return
hashMap.isEmpty(); }
public
Set<K> keySet() {
return
hashMap.keySet(); }
public
V put(K key, V value)
{
return
hashMap.put(key, value);
}
public
void
putAll(Map<?
extends
K, ?
extends
V> m)
{
hashMap.putAll(m);
}
public
V remove(Object key)
{
return
hashMap.remove(key);
}
public
int
size() {
return
hashMap.size(); }
public
Collection<V> values()
{
return
hashMap.values();
}
}
class
GFG {
public
static
void
main(String arg[])
{
HashMapImplementation<Integer, String> hashMap
=
new
HashMapImplementation<Integer, String>();
hashMap.put(
1
,
"Kapil"
);
hashMap.put(
2
,
"Nikhil"
);
hashMap.put(
3
,
"Sachin"
);
Map<Integer, String> secondMap =
new
HashMap<Integer, String>();
secondMap.put(
4
,
"Aakash"
);
secondMap.put(
5
,
"Ravi"
);
hashMap.putAll(secondMap);
System.out.println(
"the key set of the map is "
);
Set<Integer> keySet = hashMap.keySet();
Iterator<Integer> itr = keySet.iterator();
while
(itr.hasNext())
{
System.out.print(itr.next() +
"\t"
);
}
System.out.println();
System.out.println(
"the values of the map is "
);
Iterator<String> itr1;
Collection<String> collectionValues = hashMap.values();
itr1 = collectionValues.iterator();
while
(itr1.hasNext())
{
System.out.print(itr1.next() +
"\t"
);
}
System.out.println();
System.out.println(
"the entry set of the map is "
);
Iterator<Entry<Integer, String> > eitr;
Set<Entry<Integer, String> > entrySet = hashMap.entrySet();
eitr = entrySet.iterator();
while
(eitr.hasNext())
{
System.out.println(eitr.next() +
"\t"
);
}
System.out.println(
"the hash Map contains Key 3 :"
+ hashMap.containsKey(
3
));
System.out.println(
"the hash Map contains Value Mohan :"
+ hashMap.containsValue(
"Mohan"
));
System.out.println(
"the size of the hash Map is "
+ hashMap.size());
hashMap.clear();
if
(hashMap.isEmpty())
System.out.println(
"the hash Map is empty"
);
else
System.out.println(
"the hash Map is not empty"
);
}
}