Answers for "hash map java"

10

new hashmap java

Map<String, String> myMap = new HashMap<String, String>() {{
        put("a", "b");
        put("c", "d");
    }};
Posted by: Guest on May-21-2020
22

java hashmap syntax

// Import the HashMap class
import java.util.HashMap;

	// First Example
    // Create a HashMap object called capitalCities
    HashMap<String, String> capitalCities = new HashMap<String, String>();

    // Add keys and values (Country, City)
    	capitalCities.put("England", "London");
    	capitalCities.put("Germany", "Berlin");
    	capitalCities.put("Norway", "Oslo");
    	capitalCities.put("USA", "Washington DC");
    	System.out.println(capitalCities);

	//Second Example
	// Create a HashMap object called stGrade
	Map<String, Integer> stGrade = new HashMap<String, Integer>(); 

	// Insert elements 
       	stGrade.put("aaron", new Integer(90)); 
       	stGrade.put("isaac", new Integer(100)); 
       	stGrade.put("john", new Integer(35)); 
       	stGrade.put("mohammad", new Integer(100)); 

	// Get value
	   	stGrade.get("mohammad"); 	// returns 100
		stGrade.get("aaron"); 		// returns 90
		stGrade.get("john");	 	// returns 35
		stGrade.get("isaac"); 		// returns 100
Posted by: Guest on June-08-2020
1

hash map java

HashMap hm=new HashMap(int initialCapacity, float loadFactor);
Posted by: Guest on October-13-2021
0

create map java

Map<String, Integer> map = new HashMap<>();
Posted by: Guest on January-15-2021
0

declare hashmap java

//remember to first import java.util.*; first

//you can swap out string or integer for other data types
Map<String, Integer> d = new HashMap<>();
Posted by: Guest on February-20-2020
6

java hashmap example

//Hash map creation
Map< String,Integer> hm =  
                        new HashMap< String,Integer>(); 
//inserting elements into hashmap
       hm.put("a", new Integer(100)); 
       hm.put("b", new Integer(200)); 
       hm.put("c", new Integer(300)); 
       hm.put("d", new Integer(400));
Posted by: Guest on April-27-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language