hashmap in 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 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
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"HashMap<Integer,String> map=new HashMap<Integer,String>();//key is integer, value is Stringimport java.util.HashMap; // import the HashMap class
HashMap<String, String> capitalCities = new HashMap<String, String>();
Also in Java:
- Title
- java how to compare strings
- Category
- Java
- Title
- java find duplicates in array
- Category
- Java
- Title
- how to convert string to double in android studio
- Category
- Java
- Title
- java comments
- Category
- Java
- Title
- java random number generator in range
- Category
- Java
- Title
- read csv in java in spring
- Category
- Java
- Title
- abstraction in java
- Category
- Java
- Title
- how to read to into a file in java
- Category
- Java
- Title
- how to get a user input in java
- Category
- Java
- Title
- print a letter in java
- Category
- Java
- Title
- how to reverse a list in java
- Category
- Java
- Title
- saving String character in arraylist
- Category
- Java
- Title
- java generic calling clone method
- Category
- Java
- Title
- how to instanciate map.entry java
- Category
- Java
- Title
- transformer un string en double java
- Category
- Java
- Title
- how to make a pre set list java
- Category
- Java
- Title
- spigot actionbar
- Category
- Java
- Title
- java djikstra's algorithm
- Category
- Java
- Title
- java console text color
- Category
- Java
- Title
- java switch
- Category
- Java
- Title
- java php object
- Category
- Java
- Title
- Java array nested equals
- Category
- Java
- Title
- how intent
- Category
- Java
- Title
- java string replace character at position
- Category
- Java
- Title
- arraylist java methds
- Category
- Java
- Title
- spring iterate
- Category
- Java
- Title
- java interfaces
- Category
- Java
- Title
- character at index of string java
- Category
- Java
- Title
- how to append to an array in java
- Category
- Java
- Title
- generate all prime number less than n java
- Category
- Java
- Title
- transformer un string en Biginteger java
- Category
- Java
- Title
- java creare costante
- Category
- Java
- Title
- java initialize int array
- Category
- Java
- Title
- enum java
- Category
- Java
- Title
- java map example
- Category
- Java
- Title
- java list of a class has a string that is equal to
- Category
- Java
- Title
- main class java
- Category
- Java
- Title
- how to read a csv file java
- Category
- Java
- Title
- how to get all the names of the files in a folder in java?
- Category
- Java
- Title
- processing sound library
- Category
- Java
- Title
- string to double java
- Category
- Java
- Title
- java final meaning
- Category
- Java
- Title
- properties java 8 maven in pom xml
- Category
- Java
- Title
- BoxLayout java
- Category
- Java
- Title
- java int passed by reference
- Category
- Java
- Title
- exponents java
- Category
- Java
- Title
- abstract class in java
- Category
- Java
- Title
- faire un timer en java
- Category
- Java
- Title
- android get distance between two locations kotlin
- Category
- Java
- Title
- get value textfield java
- Category
- Java
- Title
- Unhandled exception: java.lang.InterruptedException
- Category
- Java
- Title
- raspberry stackexchange how to install the java jdk
- Category
- Java
- Title
- java make arraylist
- Category
- Java
- Title
- java instantiate collection with values
- Category
- Java
- Title
- how to get multiple integer input in java
- Category
- Java
- Title
- array string java in one line
- Category
- Java
- Title
- how to crate a list in java script
- Category
- Java
- Title
- write file java
- Category
- Java
- Title
- java taking console input
- Category
- Java
- Title
- android get sdk version
- Category
- Java
- Title
- java.sql.SQLException: Before start of result set
- Category
- Java
- Title
- javafx polygon
- Category
- Java
- Title
- how to add a keylistener to a jframe
- Category
- Java
- Title
- import scanner
- Category
- Java
- Title
- java map foreach
- Category
- Java
- Title
- java method overriding
- Category
- Java
- Title
- generate objects with for loop java
- Category
- Java
- Title
- thread sleep java
- Category
- Java
- Title
- int to string java
- Category
- Java
- Title
- room insert and return id
- Category
- Java
- Title
- java mockito any string import
- Category
- Java
- Title
- how to pass enum in postman body
- Category
- Java
- Title
- Fragment DashboardFragment not associated with a fragment manager.
- Category
- Java
- Title
- Kotlin is like java
- Category
- Java
- Title
- java run project from command line
- Category
- Java
- Title
- java check if file exists
- Category
- Java
- Title
- create java windows application
- Category
- Java
- Title
- why python is slower than java
- Category
- Java
- Title
- spring-boot actuator not working
- Category
- Java
- Title
- how to split string with dolor sign in java
- Category
- Java
- Title
- convert char to string java
- Category
- Java
- Title
- Enums injava
- Category
- Java
- Title
- Spring Security JWT Authentication + PostgreSQL – RestAPIs SpringBoot + Spring MVC + Spring JPA
- Category
- Java
- Title
- convert date to calendar java
- Category
- Java
- Title
- java math.random
- Category
- Java
- Title
- calculating the percentile in java
- Category
- Java
- Title
- how to iterate hashset in java 8
- Category
- Java
- Title
- java function that returns the index of the largest value in an array
- Category
- Java
- Title
- how to do 4th root java
- Category
- Java
- Title
- print map java
- Category
- Java
- Title
- how to read file from assets folder in android
- Category
- Java
- Title
- spigot custom join message
- Category
- Java
- Title
- override java
- Category
- Java
- Title
- declare class variable in java
- Category
- Java
- Title
- java cmd install raspbian
- Category
- Java
- Title
- récupérer les données d un liste java
- Category
- Java
- Title
- jquery set data attribute value
- Category
- Java
- Title
- java classes and methods
- Category
- Java
- Title
- java 8 iterating and manipulating list
- Category
- Java
- Title
- abs in java
- Category
- Java