要用60个零初始化列表,请执行以下操作:
List<Integer> list = new ArrayList<Integer>(Collections.nCopies(60, 0));
如果你想用60个不同的对象创建一个列表,你可以使用Stream API和a Supplier
,如下所示:
List<Person> persons = Stream.generate(Person::new)
.limit(60)
.collect(Collectors.toList());
原文:https://www.cnblogs.com/satire/p/14888009.html