Use the Map interface to store key-value pairs. It’s great for lookups by key.
Source Code
import java.util.HashMap;
import java.util.Map;
public class TestMap {
public static void main(String[] args) {
Map map = new HashMap();
map.put("Alice", 30);
map.put("Bob", 25);
System.out.println(map.get("Alice")); // Access elements
}
}