emboole emboole - 1 year ago 92
Java Question

YouTube's response array, sorting programatically

i'm creating an app where i get a youtube search. It is currently working ok, i just want to show better results, by sorting them by title name.

I got a VideoListResponse with 50 items

VideoListResponse videoListResponse = null;
try {
videoListResponse = mYouTubeDataApi.videos()
.setId(TextUtils.join(",", videoIds)).execute();
} catch (IOException e) {

and i want to sort them by title. Let me show an image of the item list:

sort by title

i'm pretty much stuck with this, thank you guys !

Answer Source

You could retrieve the List within and sort that:

List<Video> items = videoListResponse.getItems();
items.sort(Comparator.comparing(e -> e.getSnippet().getTitle()));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download