List<xx> candidate = abc.getxxlist();
if (candidate != null && candidate.size() >= 15) {
//取15个随机各不相同的数字
Set<Integer> randomId = new HashSet<Integer>(15);
Random r = new Random();
int max = candidate.size() > 100 ? 100 : candidate.size(); while (randomId.size() < 15) {
randomId.add(r.nextInt(max));
}
List<xx> winner = new ArrayList<xx>(15); //填充15个对象. for (Iterator<Integer> it = randomId.iterator(); it.hasNext();) {
winner.add(candidate.get(it.next()));
}
if (candidate != null && candidate.size() >= 15) {
//取15个随机各不相同的数字
Set<Integer> randomId = new HashSet<Integer>(15);
Random r = new Random();
int max = candidate.size() > 100 ? 100 : candidate.size(); while (randomId.size() < 15) {
randomId.add(r.nextInt(max));
}
List<xx> winner = new ArrayList<xx>(15); //填充15个对象. for (Iterator<Integer> it = randomId.iterator(); it.hasNext();) {
winner.add(candidate.get(it.next()));
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货