For loop to add custom objects to arraylist for n times - Java8
问题 We have an old-style for loop to add custom objects to ArrayList. public List<Object> generateList() { List<Object> list = new ArrayList<Object>(); for (int i = 0; i < 10; i++) { list.add(new Manager(50000, 10, "Finance Manager")); list.add(new Employee(30000, 5, "Accounts")); } return list; } Is there any way to do this by using java8? I tried to use Stream.generate(MyClass::new).limit(10); but, I am not getting the right way in java8 to achieve the above functionality. Any suggestions,