开发者

How to randomize the entries in a List so the user sees a different DailyPrayer each time?

开发者 https://www.devze.com 2023-01-20 23:32 出处:网络
I have a method that does a lookup of some elements and returns them to the user: List<DailyPrayer> dailyPrayers = (List<DailyPrayer>) query.execute();

I have a method that does a lookup of some elements and returns them to the user:

List<DailyPrayer> dailyPrayers = (List<DailyPrayer>) query.execute();
return dailyPrayers;

These are daily prayers so I want the user to see a different prayer each time so they do not get bored with seeing the same content in the sam开发者_运维知识库e order over and over.

How can I randomize the List?


Collections.shuffle(list)

Randomly permutes the specified list using a default source of randomness. All permutations occur with approximately equal likelihood.


You can use Collections.shuffle(dailyPrayers);


shuffle(List<?> list)
          Randomly permutes the specified list using a default source of randomness.
0

精彩评论

暂无评论...
验证码 换一张
取 消