lasan
🧩 Syntax:
import java.util.Collection;
import java.util.HashMap;
import java.util.Set;
import java.util.Iterator;
import java.util.Map;
// import javax.swing.text.html.HTMLDocument.Iterator;
class Test
{
public static void main(String[] args) {
HashMap<Integer,String> hm1=new HashMap<>();
System.out.println("Size:"+hm1.size());
System.out.println("---End of Size Method---");
System.out.println("Is Empty:"+hm1.isEmpty());
System.out.println("---End of IsEmpty Method---");
hm1.put(1, "Arman");
hm1.put(2, "Lucky");
hm1.put(3, "Dhairya");
System.out.println("Hm1->"+hm1);
System.out.println(hm1.put(3, "Sumit"));
System.out.println("Hm1->"+hm1);
System.out.println(hm1.put(4, "Arman"));
System.out.println("Hm1->"+hm1);
hm1.put(null, "viren");
System.out.println("Hm1->"+hm1);
System.out.println(hm1.put(null, "Siya"));
System.out.println("Hm1->"+hm1);
System.out.println("---End of Put Method---");
System.out.println(hm1.remove(null));
System.out.println("Hm1->"+hm1);
System.out.println(hm1.remove(5));
System.out.println(hm1.remove(3,"SUM"));
System.out.println("Hm1->"+hm1);
System.out.println("---End of Remove Method---");
HashMap<Integer,String> hm2=new HashMap<>();
System.out.println(hm2.put(3,"dju"));
System.out.println("Hm2->"+hm2);
hm1.putAll(hm2);
System.out.println("Hm1->"+hm1);
System.out.println(hm1.get(1));
System.out.println(hm1.get(2));
System.out.println(hm1.get(3));
System.out.println(hm1.get(4));
System.out.println(hm1.get(5));
System.out.println("---End of Put & PutAll Method---");
System.out.println(hm1.containsKey(1));
System.out.println(hm1.containsKey(2));
System.out.println(hm1.containsKey(3));
System.out.println(hm1.containsKey(4));
System.out.println(hm1.containsKey(5));
System.out.println("---End of ContainsKey Method---");
System.out.println(hm1.containsValue("Arman"));
System.out.println(hm1.containsValue("dju"));
System.out.println("---End of ContainsValue Method---");
hm1.clear();
System.out.println("Hm1->"+hm1);
System.out.println("---End of Clear Method---");
HashMap<Integer,String> hm3=new HashMap<>();
hm3.put(1,"A");
hm3.put(2,"B");
hm3.put(3,"C");
System.out.println("Hm3->"+hm3);
System.out.println(hm3.keySet());
Set keyHm3=hm3.keySet();
System.out.println(keyHm3);
Iterator itr2=hm3.keySet().iterator();
while (itr2.hasNext()) {
System.out.println(itr2.next());
}
System.out.println("---End of SetKey Method---");
System.out.println(hm3.values());
Collection valuehm3=hm3.values();
System.out.println(valuehm3);
Iterator itr3=hm3.values().iterator();
while (itr3.hasNext()) {
System.out.println(itr3.next());
}
System.out.println("---End of Values Method---");
System.out.println(hm3.entrySet());
Set entryhm3=hm3.entrySet();
System.out.println(entryhm3);
Iterator itr1=hm3.entrySet().iterator();
while (itr1.hasNext()) {
System.out.println(itr1.next());
}
System.out.println("---End of EntrySet Method---");
Iterator itr4=hm3.entrySet().iterator();
while (itr4.hasNext()) {
Map.Entry entry=(Map.Entry)itr4.next();
System.out.println(entry.getKey()+"-->"+entry.getValue());
}
for(Map.Entry m:hm3.entrySet())
{
System.out.println(m.getKey()+"-->"+m.getValue());
}
}
}