hashmaps java
Java
// Import the HashMap class
import java.util.HashMap;
// 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);//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)); import java.util.HashMap; // import the HashMap class
HashMap<String, String> capitalCities = new HashMap<String, String>();
import java.util.HashMap;
//Within a class
//You can do new HashMap<Key Type, Value Type>();, but you don't need to
HashMap<Int, String> examplehashmap=new HashMap<>();
{
//put in values
examplehashmap.put(5, "example");
};
//get value
examplehashmap.get(5);
//returns "example"// 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
Also in Java:
- Title
- how to reverse a list in java
- Category
- Java
- Title
- java animated gif example
- Category
- Java
- Title
- how to declare string array in java
- Category
- Java
- Title
- reading string after double in java
- Category
- Java
- Title
- how to make a char uppercase in java
- Category
- Java
- Title
- java new string array
- Category
- Java
- Title
- properties java 8 maven in pom xml
- Category
- Java
- Title
- java generic calling clone method
- Category
- Java
- Title
- sieve in java
- Category
- Java
- Title
- java merge sort
- Category
- Java
- Title
- java 8 add whole array to jsonarray
- Category
- Java
- Title
- how to get the dimensions of a 2d array in java
- Category
- Java
- Title
- is self divisor java
- Category
- Java
- Title
- java boolean even number
- Category
- Java
- Title
- java nextpermutation
- Category
- Java
- Title
- what is static setter and getter examples in java
- Category
- Java
- Title
- processing play sound
- Category
- Java
- Title
- java mockito any string import
- Category
- Java
- Title
- integer to string java
- Category
- Java
- Title
- java string to double
- Category
- Java
- Title
- Java for loop
- Category
- Java
- Title
- processing string to int
- Category
- Java
- Title
- how to remove all whitespace from string java
- Category
- Java
- Title
- how to return the lower of two values in one line java
- Category
- Java
- Title
- executors java
- Category
- Java
- Title
- java append to array
- Category
- Java
- Title
- bukkit scheduled task
- Category
- Java
- Title
- java import text file into arraylist
- Category
- Java
- Title
- java read from connection even if 404
- Category
- Java
- Title
- treemap get order java
- Category
- Java
- Title
- how to read in a file in java
- Category
- Java
- Title
- convert array to list java
- Category
- Java
- Title
- socket in java
- Category
- Java
- Title
- java string to boolean
- Category
- Java
- Title
- Spring Security JWT Authentication + PostgreSQL – RestAPIs SpringBoot + Spring MVC + Spring JPA
- Category
- Java
- Title
- java read string input
- Category
- Java
- Title
- java linked list functions
- Category
- Java
- Title
- java script print date in YYYY-MM-DD HH:MM:SS format
- Category
- Java
- Title
- can we overload a static method in java
- Category
- Java
- Title
- méthode retourne nom classe java
- Category
- Java
- Title
- dice in java
- Category
- Java
- Title
- java convert a string to char[]
- Category
- Java
- Title
- how to break from a loop in java
- Category
- Java
- Title
- inheritance in java
- Category
- Java
- Title
- programa que convierete un archi de c a java
- Category
- Java
- Title
- java insert array
- Category
- Java
- Title
- separateur JMenu swing java
- Category
- Java
- Title
- java array declaration
- Category
- Java
- Title
- javafx detect collision
- Category
- Java
- Title
- how to change the color of a menubar in java
- Category
- Java
- Title
- how to make a pre set list java
- Category
- Java
- Title
- how to check type of primitive value in java
- Category
- Java
- Title
- java load image
- Category
- Java
- Title
- android java retrofit offline cache
- Category
- Java
- Title
- arraylist with values java
- Category
- Java
- Title
- déclarer un tableau en java
- Category
- Java
- Title
- eclipse does not support logback with spring boot
- Category
- Java
- Title
- how to pass parameters to xsl file
- Category
- Java
- Title
- java how to serialize a file into a local server
- Category
- Java
- Title
- spigot run command as console
- Category
- Java
- Title
- most common element in list java
- Category
- Java
- Title
- random number in range java
- Category
- Java
- Title
- working with buttons in applet java
- Category
- Java
- Title
- how to install java 8 on terminal os
- Category
- Java
- Title
- sort elements with sortedset
- Category
- Java
- Title
- java delay
- Category
- Java
- Title
- how to get the width and height of a string in java
- Category
- Java
- Title
- read csv in java in spring
- Category
- Java
- Title
- java check if element exists in array
- Category
- Java
- Title
- all data types in java
- Category
- Java
- Title
- summary of operator java
- Category
- Java
- Title
- create object of static class in java
- Category
- Java
- Title
- date format in java
- Category
- Java
- Title
- height constraint layout guideline
- Category
- Java
- Title
- 2d array length in java
- Category
- Java
- Title
- how to send http post create request using curl command
- Category
- Java
- Title
- int to long java
- Category
- Java
- Title
- android java how to stop users fromgoing back too much
- Category
- Java
- Title
- convert hashset to int array java
- Category
- Java
- Title
- java script to detect and launch all browsers
- Category
- Java
- Title
- Java If statemtn
- Category
- Java
- Title
- trees in java
- Category
- Java
- Title
- java taking console input
- Category
- Java
- Title
- displaying an arraylist in java
- Category
- Java
- Title
- toString convert to long
- Category
- Java
- Title
- java 8 function supplier consumer
- Category
- Java
- Title
- how to input in java
- Category
- Java
- Title
- array methods in java
- Category
- Java
- Title
- objectoutputstream exemple
- Category
- Java
- Title
- java how to change the length of an array
- Category
- Java
- Title
- length of string java
- Category
- Java
- Title
- convert int to string java
- Category
- Java
- Title
- parallel sorting in java 8
- Category
- Java
- Title
- if en une seul ligne java
- Category
- Java
- Title
- how to create a java jframe
- Category
- Java
- Title
- java Convert a string IPv4 IP address to the equivalent long numeric value.
- Category
- Java
- Title
- split method in java
- Category
- Java
- Title
- java getter
- Category
- Java
- Title
- how to compare current date and time with another date and time in android
- Category
- Java
- Title
- how to create an array of arraylist in java
- Category
- Java