Returns the value for the key, or a default if not found.
Syntax
map.getOrDefault(key, default)Example
Enter values below to update the example in real time.
Map→String→scores→new→HashMap→put→System→out→println→getOrDefault→Map<String, Integer> scores = new HashMap<>();
scores.put("Alice", 90);
System.out.println(scores.getOrDefault("Bob", 0)); // 0