Java Quiz: HashMap

This Java quiz tests how HashMap really behaves. You will predict what put(), get(), getOrDefault(), merge() and computeIfAbsent() return, see why keys need both equals() and hashCode(), and handle null values safely.

मीडियम 10 सवाल ~6 मिनट पास होने के लिए 80% Java 17

मोड चुनें

आप गेस्ट के तौर पर खेल रहे हैं: XP और streak सेव रखने के लिए साइन इन करें।

सैंपल सवाल

सवाल 1 / 10

What does this print?

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

public class Main {
    public static void main(String[] args) {
        Map<String, Integer> m = new HashMap<>();
        System.out.println(m.put("a", 1) + " " + m.put("a", 2) + " " + m.get("a"));
    }
}
जवाब दिखाएं

C. null 1 2 put() returns the value previously stored for the key: null the first time, then 1. The second put() replaces the value, so get() returns 2.

इस क्विज़ में क्या है

  • put() returns the old value, get() returns null when missing
  • Counting and grouping with merge() and computeIfAbsent()
  • Keys need matching equals() and hashCode()
  • null values, containsKey() and unboxing
  • Iteration order: HashMap, LinkedHashMap, TreeMap

अक्सर पूछे जाने वाले सवाल

क्या अकाउंट ज़रूरी है?

नहीं। कोई भी खेल सकता है। XP, streak, badge और हिस्ट्री सेव रखने के लिए साइन इन करें।

क्या मैं इसे दोबारा दे सकता हूं?

हां। आपका बेस्ट स्कोर सेव रहता है, और हर बार सवाल और जवाब शफ़ल होते हैं।