如何从列表中随机提取特定数字的记录?

2026-04-10 13:271阅读0评论SEO基础
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计129个文字,预计阅读时间需要1分钟。

如何从列表中随机提取特定数字的记录?

根据您的要求,以下是简化后的代码内容:

如何从列表中随机提取特定数字的记录?

javapublic List getSubStringByRadom(List list, int count) { List backList=new ArrayList(); Random random=new Random(); int backSum=0; if (list.size()==count) { backSum=count; } return backList;}

根据指定的List和取出数得到子List

public List getSubStringByRadom(List list, int count){ List backList = null; backList = new ArrayList (); 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; }

标签:记录

本文共计129个文字,预计阅读时间需要1分钟。

如何从列表中随机提取特定数字的记录?

根据您的要求,以下是简化后的代码内容:

如何从列表中随机提取特定数字的记录?

javapublic List getSubStringByRadom(List list, int count) { List backList=new ArrayList(); Random random=new Random(); int backSum=0; if (list.size()==count) { backSum=count; } return backList;}

根据指定的List和取出数得到子List

public List getSubStringByRadom(List list, int count){ List backList = null; backList = new ArrayList (); 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; }

标签:记录