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

Answer by Randyaa for Initialization of an ArrayList in one line

$
0
0

If you need a simple list of size 1:

List<String> strings = new ArrayList<String>(Collections.singletonList("A"));

If you need a list of several objects:

List<String> strings = new ArrayList<String>();Collections.addAll(strings,"A","B","C","D");

Viewing all articles
Browse latest Browse all 37

Trending Articles



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