Java List随机取值

方法1

    public static void main(String[] args) {

        List list = Arrays.asList("a","b","c");

        int index = (int) (Math.random()* list.size());

        System.out.println(list.get(index));
    }

方法2

    public static void main(String[] args) {

        List list = Arrays.asList("a","b","c");

        // shuffle 打乱顺序 
        Collections.shuffle(list);
        System.out.println(list.get(0));
    }

你可能感兴趣的:(java,list,随机取值,JAVA)