Map map = new HashMap();
List listNew = new ArrayList();
if (list.size() <= n) {
return gson.toJson(list);
} else {
while (map.size() < n) {
int random = (int) (Math.random() * list.size());
if (!map.containsKey(random)) {
map.put(random, "");
System.out.println(random + "===========" + list.get(random));
listNew.add(list.get(random));
}
}
}
【Java】随机n个list的值
猜你喜欢
转载自blog.csdn.net/wjx_jasin/article/details/84952564
今日推荐
周排行