DEV Community

Vasanth S
Vasanth S

Posted on

1

Playing with HashMap<>(); in java

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

}

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay