I am trying to create a new Page using a list of objects retrieved from the database. First, I get all the elements from the database, convert them to a stream, and then use lambda to filter the results. Then I need a page with a given number of elements, however creating a new PageImpl does not return a page with the correct size.
Here is my code:
List<Produtos> listaFinal; Stream<Produtos> stream = produtosRepository.findAll().stream(); listaFinal = stream.filter(p -> p.getProdNome().contains("uio")).collect(Collectors.toList()); long total = listaFinal.size(); Page<Produtos> imp = new PageImpl<>(listaFinal,pageable,total);
Here is a debug screenshot:

Notice that the size in the Pageable is set to 20, and he understands that he needs 4 pages to render 70 elements, but he returns the whole list.
What am I missing?
Edit response to comment made by Thomas:
I understand how to use the page to return the entire piece of data. The code I showed was my attempt to use a lambda expression to filter my collection. The problem for me is that I want to use Java 8 lambda to query a database through Spring Data JPA. I used expressions for VB.NET and Entity function(x) queries and wondered how to do the same with Spring JPA.
In my repository I use extends JpaRepository<Produtos, Integer>, QueryDslPredicateExecutor<Produtos> , which gives me access to findAll(Predicate,Pageable) . However, the predicate is not typed, so I can’t just use p -> p.getProdNome().contains("uio") in the request. I am using SQL Server and Hibernate.
source share