020-003-010

HashMap Basic Operations

Easy

Problem Description

HashMap Basic Operations

In this problem: You will use basic HashMap operations (put/get/containsKey) to manage fruit inventory and display results to standard output.

Learning Objective: Understand basic key-value operations of HashMap

Overview

Use HashMap<String, Integer> with fruit names as keys and stock counts as values.

Specifications

  • Create a HashMap<String, Integer>
  • Use put to add three fruits: "apple"=5, "banana"=3, "cherry"=8
  • Use get to display the stock of "banana"
  • Use containsKey to check if "grape" exists
  • Display the map size

Output Format

Banana stock: 3
Has grape: false
Total fruits: 3

Ready to Try Running Code?

Log in to access the code editor and execute your solutions for this problem.

Don't have an account?

Sign Up