0

I'm curious, When declaring ArrayLists, What is the difference in doing this:

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

and this:

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

i.e. not declaring the <String> twice?

2 Answers2

1

the only difference is that the first form is compatible with earlier java versions than java 7.

Leo
  • 6,480
  • 4
  • 37
  • 52
-2

And you don't need the <> either in latter versions. e.g

List<String> arrayList2= new ArrayList();
RichieHH
  • 2,116
  • 4
  • 28
  • 30
  • This is *not* the same thing. Here, you're assigning a raw type to a generic variable, and so do *not* get the type safety generics provides. – awksp May 29 '14 at 14:39
  • For more information about raw types, see [this section](http://www.angelikalanger.com/GenericsFAQ/FAQSections/ParameterizedTypes.html#Raw) of the excellent GenericsFAQ. – Edd May 29 '14 at 14:51