Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert a page of objects to list in spring data

I have a page of objects like this:

Page<Video> videos = videoRepository.findAllVideos(new PageRequest(1, 50)); 

How can I convert that to a list of Video objs without iterating over my page?

like image 617
DanielD Avatar asked Aug 25 '16 00:08

DanielD


People also ask

How do you turn an object into a list?

//Assuming that your object is a valid List object, you can use: Collections. singletonList(object) -- Returns an immutable list containing only the specified object. //Similarly, you can change the method in the map to convert to the datatype you need.

How do I convert a list of strings to a list of objects?

Pass the List<String> as a parameter to the constructor of a new ArrayList<Object> . List<Object> objectList = new ArrayList<Object>(stringList); Any Collection can be passed as an argument to the constructor as long as its type extends the type of the ArrayList , as String extends Object .

What is Page <> in Java?

A page is a sublist of a list of objects. It allows gain information about the position of it in the containing entire list.

Which can convert an object into a list in Java?

1 Answer. Explanation: singletonList() returns the object as an immutable List. This is an easy way to convert a single object into a list. This was added by Java 2.0.


1 Answers

Page<Video> videos = videoRepository.findAllVideos(new PageRequest(1, 50)); List<Video> videosList = videos.getContent(); 

You can use the above code to get the list of videos from page

like image 195
Sathyendran a Avatar answered Sep 20 '22 13:09

Sathyendran a