• Home
  • LLMs
  • Python
  • Docker
  • Kubernetes
  • Java
  • Maven
  • All
  • About
Java | HashMap
  1. Notes
  2. Example

  1. Notes
    Unsorted entries
    Unordered entries
    Duplicates elements not allowed
  2. Example
    HashMap<Integer, String> hm = new HashMap<>();
    
    hm.clear();
    // hm.put(null, "x"); // ok
    // hm.put(0, null); // OK
    hm.put(0, "a");
    hm.put(11, "f");
    hm.put(222, "e");
    hm.put(3333, "d");
    hm.put(44444, "c");
    hm.put(555555, "b");
    hm.put(6666666, "g");
    
    for (Map.Entry<Integer, String> entry : hm.entrySet()) {
        System.out.println(entry.getKey() + " = " + entry.getValue());
    }
    Output:
    0 = a
    3333 = d
    11 = f
    555555 = b
    44444 = c
    222 = e
    6666666 = g
© 2025  mtitek