When declaring a list in java.... | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
0

When declaring a list in java....

Is ArrayList<String> listA = new ArrayList<>(); And ArrayList<String> listA = new ArrayList<String>(); The same? One of them contains "String" on both side of the operator and the other only on one side.

22nd Sep 2022, 1:39 PM
Lenoname
3 ответов
+ 5
Have you tried testing out the code yourself to see? Experimentation is one of the best part of programming in my opinion because it helps you learn and answer our own questions.
22nd Sep 2022, 2:25 PM
Justice
Justice - avatar
+ 5
Lenoname In Latest Java version no need to write same thing on right side. You can left with only diamond operator.
22nd Sep 2022, 3:15 PM
A͢J
A͢J - avatar
+ 2
To respect the principle of SOLID, it is preferable to use the parent class or interface to initialize the variables: List<String> named = New ArrayList<>()
24th Sep 2022, 6:47 AM
Roland
Roland - avatar