hashmap java
private static final Map<Integer, String> map = Map.of(
1, "one",
2, "two"
);
hashmap java
private static final Map<Integer, String> map = Map.of(
1, "one",
2, "two"
);
Implementation of HashMap Class in Java map
// Java Program to illustrate the Hashmap Class
// Importing required classes
import java.util.*;
// Main class
public class Main {
// Main driver method
public static void main(String[] args)
{
// Creating an empty HashMap
Map<String, Integer> hashmap = new HashMap<>();
// Inserting entries in the Map
// using put() method
hashmap.put("Banana", 100);
hashmap.put("Orange", 200);
hashmap.put("Mango", 300);
hashmap.put("Apple", 400);
// Iterating over Map
for (Map.Entry<String, Integer> e : hashmap.entrySet())
// Printing key-value pairs
System.out.println(e.getKey() + " "+ e.getValue());
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us