~/ learn/ java-from-zero/ cards/ Generics
1 of 24

Type a List<String> with the diamond operator

Type a List<String> with the diamond operator

Answer

List<String> names = new ArrayList<>();

The diamond <> tells the compiler to infer the type argument from the left-hand side declaration. No cast needed when you call names.get(i).

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