~/ learn/ java-from-zero/ cards/ Framework overview: Collection vs Map
1 of 3

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/e17f6566-5fd0-4dc0-a6b0-8b23459362fb/flashcard utf-8 LF