/*
* author:wsx
*/
public List<TSDepart> getSubStringByRadom(List<TSDepart> list, int count){
List backList = null;
backList = new ArrayList<TSDepart>();
Random random = new Random();
int backSum = 0;
if (list.size() >= count) {
backSum = count;
}else {
backSum = list.size();
}
for (int i = 0; i < backSum; i++) {
// 随机数的范围为0-list.size()-1
int target = random.nextInt(list.size());
backList.add(list.get(target));
list.remove(target);
}
return backList;
}
Java中随机抽取List集合中特定个数的子项
最新推荐文章于 2024-07-31 04:28:28 发布