~/ 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/717287d1-4b12-4880-8457-fe6d235bbad4/flashcard utf-8 LF