import java.util.*;
import java.lang.*;
class Main {
public static void main(String[] args) {
Map<String,Integer> phone = new HashMap<>();
phone.put("Barack Obama", 111111);
phone.put("Donald Trump", 222222);
phone.put("Joe Biden", 3333333);
System.out.println(phone.size());
System.out.println(phone.containsKey("Barack Obama"));
System.out.println(phone.containsKey("Donald Trump"));
System.out.println(phone.get("Barack Obama"));
System.out.println(phone.get("Bill Clinton"));
// using keySet()
for (String s: phone.keySet()) {
Integer value = phone.get(s);
System.out.println(s + " -> " + value);
}
System.out.println("####");
// using values()
System.out.println(phone.values());
System.out.println("####");
// using entrySet()
for (Map.Entry<String, Integer> e: phone.entrySet()) {
String key = e.getKey();
Integer value = e.getValue();
System.out.println(key + " -> " + value);
}
System.out.println("####");
// using stream api
phone.entrySet()
.stream()
.filter(x -> !x.getKey().contains("B"))
.map(x -> x.getValue())
.forEach(System.out::println);
}
}
To embed this program on your website, copy the following code and paste it into your website's HTML: