Java Random randomList(Collection collection)

Here you can find the source of randomList(Collection collection)

Description

random List

License

Open Source License

Declaration

public static <E> List<E> randomList(Collection<E> collection) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.*;

public class Main {
    public static <E> List<E> randomList(Collection<E> collection) {

        List<E> list = new ArrayList<>(collection);
        Collections.shuffle(list);

        return list;
    }/*from  ww  w .j  a v  a  2 s.  c om*/

    public static <E> List<E> randomList(E[] elements) {

        return randomList(Arrays.asList(elements));
    }

    public static <E> List<E> asList(E[] array) {
        if (isEmpty(array)) {
            return new ArrayList<>();
        }

        return Arrays.asList(array);
    }

    private static <E> boolean isEmpty(Collection<E> collection) {

        return (collection == null || collection.isEmpty());
    }

    private static <E> boolean isEmpty(E[] array) {

        return (array == null || array.length == 0);
    }
}

Related

  1. randomIntegers(int sz)
  2. randomIterable(Collection col)
  3. randomKey()
  4. randomKey()
  5. randomLetter()
  6. randomMember(Collection collection)
  7. randomNanoTime()
  8. randomNick()
  9. randomPassword()