Quantcast
Channel: Initialization of an ArrayList in one line - Stack Overflow
Viewing all articles
Browse latest Browse all 37

Answer by Old Firm for Initialization of an ArrayList in one line

$
0
0

I suspect the original question relates to a desire to declare and initialize the ArrayList in one line and avoid having to create separate code to acheive the initialization. Thus, the answer lies in the question but may be generalized as follows:

ArrayList&lt;AnyClass> arrayListOfAnyClass = new ArrayList<>(Arrays.asList(  new AnyClass(param11, param12, ...),  new AnyClass(param21, param22, ...),  new AnyClass(param31, param32, ...),  ...));

Viewing all articles
Browse latest Browse all 37

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>