I\'m trying to use stream in java, i had a student class:
@Entity
@Data @AllArgsConstructor @NoArgsConstructor
public class Student {
@Id @GeneratedValue(str
Thank you all, your answers helped me to derive a solution:
List students= Arrays.stream(empIds)
.mapToObj(id->
studentRepository.findById(id).get())
.collect(Collectors.toList());
And the response of deadpool is great also, we have to add .map(Optional::get) to get the stream of student because studentRepository::findById return stream of optioanl that's why the error.
List students= Arrays.stream(empIds)
.mapToObj(studentRepository::findById)
// .filter(Optional::isPresent)
.map(Optional::get)
.collect(Collectors.toList());