में किसी दिए गए कुंजी के लिए कोई मान खोजें, आप HashMap
में कोई कुंजी कैसे खोजते हैं? इस कार्यक्रम में, जब उपयोगकर्ता कुंजी में प्रवेश करता है तो कोड को संबंधित मान के लिए हैशैप को खोजने और फिर इसे मुद्रित करने की व्यवस्था करनी चाहिए।हैश मैप
कृपया मुझे बताएं कि यह क्यों काम नहीं कर रहा है।
import java.util.HashMap;
import java.util.; import java.lang.;
public class Hashmapdemo
{
public static void main(String args[])
{
String value;
HashMap hashMap = new HashMap();
hashMap.put(new Integer(1),"January");
hashMap.put(new Integer(2) ,"February");
hashMap.put(new Integer(3) ,"March");
hashMap.put(new Integer(4) ,"April");
hashMap.put(new Integer(5) ,"May");
hashMap.put(new Integer(6) ,"June");
hashMap.put(new Integer(7) ,"July");
hashMap.put(new Integer(8),"August");
hashMap.put(new Integer(9) ,"September");
hashMap.put(new Integer(10),"October");
hashMap.put(new Integer(11),"November");
hashMap.put(new Integer(12),"December");
Scanner scan = new Scanner(System.in);
System.out.println("Enter an integer :");
int x = scan.nextInt();
value = hashMap.get("x");
System.out.println("Value is:" + value);
}
}
मेक उस उत्तर को स्वीकार करना सुनिश्चित करें जो इसके आगे "टिक" मारकर आपके प्रश्न का उत्तर दे। –