About 66,900 results
Open links in new tab
  1. HashMap in Java - GeeksforGeeks

    Mar 7, 2025 · In Java, HashMap is part of the Java Collections Framework and is found in the java.util package. It provides the basic implementation of the Map interface in Java. HashMap stores data in (key, value) pairs. Each key is associated with a value, and you can access the value by using the corresponding key.

  2. java - How to directly initialize a HashMap (in a literal way)?

    With Java 8 or less. You can use static block to initialize a map with some values. Example : public static Map<String,String> test = new HashMap<String, String> static { test.put("test","test"); test.put("test1","test"); } With Java 9 or more. You can use Map.of() method to initialize a map with some values while declaring. Example :

  3. Java HashMap - W3Schools

    Java HashMap. In the ArrayList chapter, you learned that Arrays store items as an ordered collection, and you have to access them with an index number (int type). A HashMap however, store items in "key/value" pairs, and you can access them by an index of another type (e.g. a String). One object is used as a key (index) to another object (value).

  4. HashMap (Java Platform SE 8 ) - Oracle

    Hash table based implementation of the Map interface. This implementation provides all of the optional map operations, and permits null values and the null key. (The HashMap class is roughly equivalent to Hashtable, except that it is unsynchronized and permits nulls.)

  5. Initialize a HashMap in Java - Baeldung

    Sep 7, 2024 · In this tutorial, we’ll learn about various ways of initializing a HashMap in Java. We’ll use Java 8 as well as Java 9.

  6. Java HashMap - Tpoint Tech

    Apr 1, 2025 · HashMap in Java is like the legacy Hashtable class, but it is not synchronized. It allows us to store the null elements as well, but there should be only one null key. Since Java 5, it is denoted as HashMap<K,V> , where K stands for key and V for value.

  7. HashMap in Java With Examples - BeginnersBook

    Sep 19, 2022 · How to declare HashMap in Java? HashMap<K, V> hmap = new HashMap<K, V>(); K: It represents the type of the key in a key-value pair. V: It represents the type of a value in a key-value pair. For example: A HashMap that has integer keys and string values can be declared like this: HashMap<Integer, String> hmap = new HashMap<Integer, String ...

  8. Complete Guide to Java HashMap (with Examples)

    Dec 5, 2024 · We can create HashMap using different ways, specific to the requirements. For example, we can create an empty HashMap containing no key-value pairs initially. Later, we can add the key-value pairs in this empty HashMap. Additionally, we can specify the initial load capacity and load factor for performance reasons discussed later in this article.

  9. HashMap in Java - Guru99

    Oct 4, 2024 · Following are the two ways to declare a Hash Map: Important Hashmap Methods. get (Object KEY) – This will return the value associated with a specified key in this Java hashmap. put (Object KEY, String VALUE) – This method stores the specified value and associates it with the specified key in this map.

  10. Java HashMap (With Examples) - Programiz

    In order to create a hash map, we must import the java.util.HashMap package first. Once we import the package, here is how we can create hashmaps in Java. In the above code, we have created a hashmap named numbers. Here, K represents the key type and V represents the type of values. For example,

  11. Some results have been removed
Refresh