Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filtering a Page

Page<K2Agents> iterable = k2AgentsRepository.findAllByTeamIdIn(teamIds, pageRequest);
List<K2Agents> iterable1 = iterable.stream()
                                   .filter(i->i.getLastName().equals(searchName))
                                   .collect(Collectors.toList());
return iterable1;

I want to filter iterable by a string searchName. The final result should be a Page. In this code iterable1 return nothing.

like image 998
Mike280977 Avatar asked Jun 02 '26 01:06

Mike280977


1 Answers

First filter the Page<K2Agent> by using stream and finally create Page object using PageImpl

List<K2Agents> result = iterable.getContent()
                                   .stream()
                                   .filter(i->i.getLastName().equals(searchName))
                                   .collect(Collectors.toList());

Page<K2Agent> r = new PageImpl<K2Agent>(result);
like image 115
Deadpool Avatar answered Jun 05 '26 01:06

Deadpool



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!