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