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?
//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.
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 .
A page is a sublist of a list of objects. It allows gain information about the position of it in the containing entire list.
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.
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
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