Playing with HashMap<>(); in java
Vasanth S

Vasanth S @vasanthvnr_31

About: I am Vasanth from the department of Information Technology, currently pursing my UG degree. I have been learning the flutter app development and also a Java programing language.

Joined:
Jan 27, 2025

Playing with HashMap<>(); in java

Publish Date: Feb 18
1 0

Today learned the intresting topic to see is HashMap Concept and play with HashMap are

output:
{2=Apple, 3=Grapes, 4=orange}
{2=Apple, 3=Grapes}
Banana
2
Cherry
0

program:
import java.util.HashMap;
import java.util.Map;

public class hashM {
public static void main(String[] args) {
Map vm=new HashMap<>();//playing with hashmap
vm.put(2,"Apple");
vm.put(3,"Grapes");
vm.put(4,"orange");
System.out.println(vm);
vm.remove(4);
System.out.println(vm);
vm.replace(3,"Banana");
System.out.println(vm.get(3));
System.out.println(vm.size());

    vm.put(4,"Cherry");
    System.out.println(vm.get(4));
    vm.clear();
    System.out.println(vm.size());
}
Enter fullscreen mode Exit fullscreen mode

}

Comments 0 total

    Add comment