I have a List<Student>
and String firstName="George"
. I want to extract Student object from List matching with "George"
without iterating list. Is it possible?
May be if some method override required or anything to make it work.
public Class Student {
private String firstName;
private String lastName;
private String class;
// getter, setter methods goes here....
}
Please help me thanks.
If you are using Java 8 then its possible using Stream and Lambda:-
List<Student> myStudent = studentsList.stream()
.filter(s -> s.name.equals("George"))
.collect(Collectors.toList());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With