How to create a list with 'n' objects using stream (java8)

//Creates a list with 'n' my objects List<MyObject> myObjects = IntStream.range(0, n) .mapToObj(i -> new MyObjec()) .collect(Collectors.toList());
Creates a list with 'n' objects without the need to use a for or previously initialize the list interface.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.