~/ learn/ java-from-zero/ cards/ Collections
1 of 23

Type a variable declared as the interface type, assigned an implementation

Type a variable declared as the interface type, assigned an implementation

Answer

List<String> names = new ArrayList<>(); Set<Integer> ids = new HashSet<>(); Map<String, Integer> scores = new HashMap<>();

Declare the variable as the interface (List, Set, Map) and assign a concrete class. This is the canonical collections idiom.

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/8fa37489-d406-4464-b339-c068afe9014a/flashcard utf-8 LF