Idea to Java ArrayLists

Pavel Rappo pavel.rappo at oracle.com
Thu Jul 9 19:05:38 UTC 2015


> On 9 Jul 2015, at 18:46, Louis Wasserman <lowasser at google.com> wrote:
> 
>  what you can do there is new ArrayList<>(Arrays.asList("1", "2", "3", "4", "5"));

Louis, sure we can do this. No problem with that. But what we are really talking
about here (as far as I understand) is a convenience. In my opinion there's no
much difference between

   new ArrayList<>(Arrays.asList("1", "2", "3", "4", "5"));

and

   ArrayList<String> l = new ArrayList<>();
   l.addAll(Arrays.asList("1", "2", "3", "4", "5"));

or

   ArrayList<String> l = new ArrayList<>();
   Arrays.asList("1", "2", "3", "4", "5").forEach(l::add);

etc. Thanks for collection types connectivity.

In other words I think the difference between readable and not-so-easily-readable
code in this particular example is very subjective. What we have here is a very
special case of creating a _small_ list of easily enumerable elements. I hope
this work [1] will solve the problem or at least will make it a lot less severe.

------------------------------------------------------------------------------
[1] https://bugs.openjdk.java.net/browse/JDK-8048330




More information about the core-libs-dev mailing list