I need to populate list of class Student:
class Student {
String firstName;
String lastName;
public Student(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
Here is the generator method signature:
public List<Student> generateRandomStudents(int quantity) {
List<Student> students;
// List is populated by required quantity of students
return students;
What I have tried:
List<Student> students = Stream
.of(new Student(getRandomStringFromFile("firstnames.txt"), getRandomStringFromFile("lastnames.txt")))
.limit(quantity)
.collect(Collectors.toList());
creates only 1 student. 2) Tried using Stream.generate, but it works only with Supplier and I can't use my arguments for the constructor.
Stream.generate? You do need a supplier here.IntStream.rangeas if you would loop,mapping to a newStudentobject each time.