~/ 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/544be74a-b662-4c43-b174-f6a925520872/flashcard utf-8 LF