You could use Stream.generate(Supplier<T>)
in combination with a reference to a constructor and then use Stream.limit(long)
to specify how many you should construct:
Stream.generate(Objects::new).limit(numOfElements).collect(Collectors.toList());
At least to me, this is more readable and illustrates intent much more clearly than using an IntStream
for iteration does as e.g. Alberto Trindade Tavares suggested.
If you want something which performs better in terms of complexity and memory usage, pass the result size to Stream.collect(Collector<? super T,A,R>)
:
Stream.generate(Objects::new).limit(numOfElements).collect(Collectors.toCollection(() -> new ArrayList<>(numOfElements)));