Create List of Employees with dynamic values using Java streams
问题 I have use case where I have to create List of default employees with incrementing id, List<Employee> employeeList = new ArrayList<>(); int count = 0; while (count++ <= 100){ Employee employee = new Employee(count, "a"+count); employeeList.add(employee); } I don't have any collection on which I could use stream. Can we do it in functional way? 回答1: You can use IntStream with rangeClosed(int startInclusive, int endInclusive) to generate the count List<Employee> employeeList = IntStream