Java 8 - fill ArrayList
问题 Is there a better way to fill an ArrayList like this (I have done it like this in Java 7): List<ScheduleIntervalContainer> scheduleIntervalContainers = new ArrayList<>(); scheduleIntervalContainers.add(scheduleIntervalContainer); 回答1: To fill a List , it is possible to generate an infinite Stream using Stream.generate(s) and then limit the number of results with limit(maxSize). For example, to fill a List of 10 new ScheduleIntervalContainer objects: List<ScheduleIntervalContainer>