I've learned today that you can create a new ArrayList object utilizing a static method like so:
List<String> listDummy = Arrays.asList("Coding", "is", "fun");
ArrayList<String> stringList = new ArrayList<>(listDummy);
Or even more concisely:
ArrayList<String> stringList = new ArrayList<>(Arrays.asList("Coding", "is", "fun"));
My question is: How expensive is this performance-wise compared to the "traditional" way? (below)
ArrayList<String> stringList = new ArrayList<>();
stringList.add("Coding");
stringList.add("is");
stringList.add("fun");
I realize the upper way of creating an ArrayList includes an extra List object creation, however, I prefer the shorter and more compact syntax to an extent that I'm willing to sacrifice some performance but gotta draw the line somewhere.
PS. leaving the type information(<>) empty in "new ArrayList<>()" is a Java SE 7 feature, not an error.
Thank you beforehand for any answers!