To fill a List
, you can create infinite Stream
with Stream.generate(s)
, and then limit the number of results with limit(maxSize)
.
For example, to fill List
out 10 new objects ScheduleIntervalContainer
:
List<ScheduleIntervalContainer> scheduleIntervalContainers =
Stream.generate(ScheduleIntervalContainer::new).limit(10).collect(toList());
The method generate
accepts Supplier
: in this case, the provider is a reference to a method that creates a new instance ScheduleIntervalContainer
each time.
source
share