What is the difference between the following two statements when initializing an ArrayList ?
ArrayList
ArrayList<String> a = new ArrayList<String>(); ArrayList<String> a = new ArrayList<>();
Before Java 1.7, only one thing is allowed:
ArrayList<String> a = new ArrayList<String>();
And in 1.7 the same thing is added, but in short: (all programmers are lazy)
ArrayList<String> a = new ArrayList<>();
The latter uses the alleged type introduced in Java 7. The syntax (known as the diamond operator) is illegal for collections prior to Java 1.7, so the former is used for these earlier versions.
The diamond operator reduces verbosity of the declaration.
There is no difference. The second option (called the Diamond Operator) is a shortcut. The compiler will conclude that the generic ArrayList type parameter must be a string.
The second option used the concept introduced in java 7 - the alleged types. Apart from this and assuming you are using java 7, the effect of the two calls should be the same. In earlier versions of Java, you cannot use the second version of your code.
Source: https://habr.com/ru/post/1490877/More articles:GIT - how to ensure file exclusion by the server? - gitGetting parseerror when getting response from json_encode using $ .ajax - jsonDisplay success message on the same page when submitted - c #Using JAW-XS annotations in Tomcat / Axis2 - javaDoes the remainder support arraialist objects? - javaXML parsing with Jsoup - javaHow to get a prepared request that is sent to db - pythonWhat does a single vertical bar and an equal bar mean in Ruby? - ruby ββ| fooobar.comVisual Studio 2012 automatically creates a virtual directory in IIS 7 at startup - iis-7Getting numbers calculated using formulas using XLConnect - rAll Articles