Color theme
0 day streak0 XPP1
JavaLearn mode
MISSION 1 OF 1

Look up an airport terminal

0 XP earned
Java track: IntermediateMission: BeginnerMapsKey lookupDefault values
Before you start this intermediate track

Variables, methods, and typed collections. The lessons use constructors, fields, and maps.

Guided code reading and debugging. Runnable coding challenges are available in JavaScript, Python, and SQL.

x
0 / 2 challenges
LEARN THE CONCEPT

Understand it, then try it.

A Map connects a key with a value, such as an airport code with its terminal. Map.of creates a small map from the supplied pairs. getOrDefault returns the stored value for an existing key and a fallback when the key is absent. This avoids displaying null for an unknown airport.

Main.java
import java.util.Map;public class Main {  public static void main(String[] args) {    Map<String, String> terminals = Map.of("SFO", "T2", "LHR", "T5");    String airport = "NRT";    String terminal = terminals.getOrDefault(airport, "unassigned");    System.out.println(airport + ": " + terminal);  }}

Each example is a complete Java 11+ source file named Main.java. Compile with javac Main.java and run with java Main. Each mission is independent.

Track the values line by line. Predict the result before running this example in your own editor.