Q:

Two ways to new ArrayList in java

Generally, I can new an ArrayList in this way(if element is String):
List<String> list = new ArrayList<String>();

However, I find a new way to do it:
List<String> list = new ArrayList<>();

It seems I can save much code by the second way if the element in the list is complex type.
Any difference between those?

A:

Type inference was added in JDK 1.7, the second style.

It seems I can save much code by the second way if the element in the list is complex type.

You it automacially infers if you are using 1.7 or +, which means the ArrayList gets the type of It's declared List.
Called as Diamond operator and purpose of the diamond operator is to simplify instantiation of generic classes.

