Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

new hashmap java

Map<String, String> myMap = new HashMap<String, String>() {{
        put("a", "b");
        put("c", "d");
    }};
Comment

Create a HashMap


      // Creating an empty HashMap
      HashMap<Integer, String> hash_map = new HashMap<Integer, String>();
  
      // Mapping string values to int keys
      hash_map.put(10, "I");
      hash_map.put(15, "Love");
      hash_map.put(20, "ZOZO");
      hash_map.put(25, "❤");
  
       
Comment

Create HashMap in Java

import java.util.HashMap;

class Main {
  public static void main(String[] args) {

    // create a hashmap
    HashMap<String, Integer> languages = new HashMap<>();

    // add elements to hashmap
    languages.put("Java", 8);
    languages.put("JavaScript", 1);
    languages.put("Python", 3);
    System.out.println("HashMap: " + languages);
  }
}
Comment

new hashmap java


// this works for up to 10 elements:
Map<String, String> test1 = Map.of(
    "a", "b",
    "c", "d"
);

// this works for any number of elements:
import static java.util.Map.entry;    
Map<String, String> test2 = Map.ofEntries(
    entry("a", "b"),
    entry("c", "d")
);

Comment

PREVIOUS NEXT
Code Example
Java :: list.of java 
Java :: java singleton 
Java :: JFrame frame = new JFrame (); 
Java :: get index of element in array java 
Java :: Java Regex : 4 Letters followed by 2 Integers 
Java :: -3 to string in java 
Java :: java list 
Java :: how to create a function in java 
Java :: reverse negative number 
Java :: argumentcaptor java mockito 
Java :: android java show hide keyboard: 
Java :: type of exception in java 
Java :: arraylist 
Java :: Java Type conversion from String to int 
Java :: remove spaces java 
Java :: java character for end of file 
Java :: parcourir un string java 
Java :: java ints to color int 
Java :: maximum arrays size in java 
Java :: replace all these caracters in string java 
Java :: constructor in java 
Java :: how to send http post create request using curl command 
Java :: localdate to string java 
Java :: transformer un string en Biginteger java 
Java :: linked list vs array list 
Java :: dowload htpasswd file java 
Java :: java create an instance of a stack 
Java :: Implementation of TreeMap Class in Java map 
Java :: no java virtual machine found after searching the following locations 
Java :: math square java 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =