ShuffleTest java 使用集合的方式进行排序

简介

使用结合的方式进行排序

TIPS

里面使用了随机打乱shuffle函数。

result

[0, 1, 10, 16, 20, 34]

code

import java.util.ArrayList;
import java.util.*;

public class ShuffleTest {
    public static void main(String[] args) {
        List<Integer> numbers = new ArrayList<>();
        for(int i=0; i<=49; i++){
            numbers.add(i);
        }
        Collections.shuffle(numbers);
        List<Integer> winningCombination = numbers.subList(0, 6);
        Collections.sort(winningCombination);
        System.out.println(winningCombination);
    }
}
Hope is a good thing,maybe the best of things,and no good thing ever dies.----------- Andy Dufresne
原文地址:https://www.cnblogs.com/eat-too-much/p/13887830.html