-1

I am a beginner in java and just getting into collection framework,
an arraylist can be declared a few ways like

List<String> list=new Arraylist<>(); 

or

Arraylist<String> list=new Arraylist<>();

each of them with or without the diamond brackets.

I Wanted to ask what are the differences between the two declarations and why use the diamond brackets if it is not needed.

Hovercraft Full Of Eels
  • 280,125
  • 25
  • 247
  • 360
  • "why use the diamond brackets if it is not needed" They are needed. If you don't use them, you've got a raw type; and [don't use those](https://stackoverflow.com/questions/2770321/what-is-a-raw-type-and-why-shouldnt-we-use-it). – Andy Turner May 31 '17 at 22:14
  • Also duplicate of [What does <> (angle brackets) mean in Java?](https://stackoverflow.com/q/6607550/642706) – Basil Bourque May 31 '17 at 22:15
  • [**Why Use Generics?**](https://docs.oracle.com/javase/tutorial/java/generics/why.html) – Ousmane D. May 31 '17 at 22:16

1 Answers1

-2

You need to declare what type of array list in the diamonds either if you go by the list collection or by the array list. And besides that in you example you have the diamonds in both

Ocirederf
  • 101
  • 1
  • 6