
是的,有一些简短的方法可以实现您所描述的内容。
例如 :
Integer[] arr = {3,6,7,11,20};List<Integer> shuffled = new ArrayList<>();for (Integer i : arr) shuffled.addAll (Collections.nCopies(x,i)); // add i to your List x timesCollections.shuffle(shuffled); // shuffle the List to get random order或者(如果您不想使用
Collections.nCopies(x,i)):
Integer[] arr = {3,6,7,11,20};List<Integer> shuffled = new ArrayList<>();for (int j = 0; j < x; j++) for (Integer i : arr) shuffled.add (i);Collections.shuffle(shuffled); // shuffle the List to get random order欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)