如何从列表中随机选取特定数量的记录项?

更新于
2026-10-04 11:28:03
2阅读来源:SEO问题
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计130个文字,预计阅读时间需要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; } // 省略剩余代码}

如何从列表中随机选取特定数量的记录项?

根据指定的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; }

标签:记录

本文共计130个文字,预计阅读时间需要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; } // 省略剩余代码}

如何从列表中随机选取特定数量的记录项?

根据指定的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; }

标签:记录