开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜