Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Initializing a collection [duplicate]

Tags:

java

What is the difference between the following two statements, in initializing an ArrayList?

ArrayList<String> a = new ArrayList<String>();
ArrayList<String> a = new ArrayList<>();
like image 775
Yaswanth Avatar asked Nov 30 '22 03:11

Yaswanth


1 Answers

Before Java 1.7, only this one is permitted:

ArrayList<String> a = new ArrayList<String>();

And in 1.7, this is added, which is the same but shorter: (all programmers are lazy)

ArrayList<String> a = new ArrayList<>();
like image 159
johnchen902 Avatar answered Dec 05 '22 13:12

johnchen902