Java67 - Java Program Example Tutorial Blog

Java67 - Java Program Example Tutorial Blog


How to create and initialize List or ArrayList in one line in Java

Posted: 05 Dec 2012 04:48 AM PST

creating and initializing List in same time
Sometime we want to create and initialize List like ArrayList or LinkedList in one line much like creating array and initializing it on same line. If you look Array on Java programming language you can create and initialize both primitive and object array e.g. String array very easily in just one line but in order to create a List equivalent of that array, you need to type lot of code. This is also one of the tricky Java question some time appears in Interview as Write Java code to create and initialize ArrayList in same line. In this Java tips we will see this trick which allow you to create and initialize List much like an Array. This tip can also save lot of time while creating test program or quickly trying some stuff.
Read more »


Post a Comment