Idea to Java ArrayLists

kedar mhaswade kedar.mhaswade at gmail.com
Thu Jul 9 17:34:16 UTC 2015


Philipp,

Wouldn't Arrays.asList
<http://docs.oracle.com/javase/8/docs/api/java/util/Arrays.html#asList-T...->
work for you?

e.g.
List<String> strings = Arrays.asList("1", "2", "3"); or
List<String> strings = Arrays.asList("1", "2", "3", "4", "five");

Regards,
Kedar

On Thu, Jul 9, 2015 at 8:55 AM, Philipp Bibik <philipp at bibik.de> wrote:

> Hi,
>
> I'm Philipp Bibik and a 16 jear old free time developer.
> I was born and live in Germany and have only an bad school english,
> so sorry for any grammar and spelling mistakes.
>
> I have an idea to improve the Java ArrayList API.
> Lists are one of the most imported and used components in the Java API.
> Although there are relay well designed, there was always something that
> annoyed me.
>
> If you want to create an ArrayList with "String" as diamond operator and
> add the Strings
> "1" to "5" to them, you need to do something like this:
>
>     ArrayList<String> strings = new ArrayList<>();
>     strings.add("1");
>     strings.add("2");
>     strings.add("3");
>     strings.add("4");
>     strings.add("5");
>
> I added a few lines of code the the ArrayList class:
>
>     /**
>      * @param e array whose elements are to be placed into this list
>      */
>     @SafeVarargs
>     public ArrayList(E... e) {
>         elementData = e;
>         size = elementData.length;
>     }
>
> After adding the lines above I was able to accomplish the same result
> with 77 chars / 5 lines less code:
>
>     ArrayList<String> strings = new ArrayList<>("1", "2", "3", "4", "5");
>
> In my opinion adding a constructor like this to the "java.util.ArrayList"
> class and
> all other (at least some) classes, implementing the "java.util.List"
> interface
> would be a big improvement to Java SE9.
>
> Thanks for reading,
>
> - Philipp Bibik.
>



More information about the core-libs-dev mailing list