A Map pairs unique keys with values. Store a score under a key, read it back with get, then ask whether another key exists. get returns null for a missing key.
import java.util.HashMap;
import java.util.Map;
class Main {
public static void main(String[] args) {
Map scores = new HashMap<>();
scores.put("Ada", 90);
int grade = scores.get("Ada");
boolean has = scores.containsKey("Cy");
System.out.println(grade);
System.out.println(has);
}
}
Before you run it, say out loud what it will print. Then open the answer.
What it prints
90
false
Keys must be unique and hashable. get returns null when the key is absent, so guard against null before treating the value as a number.