private static List createRandomList(List list, int n) {
Map map = new HashMap();
List listNew = new ArrayList();
if (list.size() <= n) {
return 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));
}
}
return listNew;
}
}
参考网址:https://blog.csdn.net/u013939884/article/details/72364761/