Skip to content

10.4 Map Interface (HashMap Internal Working)

import java.util.HashMap;
import java.util.Map;

public class MapDemo {
    public static void main(String[] args) {
        Map<String, Double> stockPrices = new HashMap<>();
        stockPrices.put("TCS", 3850.50);
        stockPrices.put("INFY", 1520.00);
        stockPrices.put("RELIANCE", 2950.75);

        System.out.println("TCS Price: ₹" + stockPrices.get("TCS"));

        for (Map.Entry<String, Double> entry : stockPrices.entrySet()) {
            System.out.println(entry.getKey() + " -> ₹" + entry.getValue());
        }
    }
}

🧭 Navigation

Last updated on