All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.guppy4j.Lists Maven / Gradle / Ivy

The newest version!
package org.guppy4j;

import java.util.List;
import java.util.concurrent.ThreadLocalRandom;

/**
 * Static helper methods for list objects
 */
public class Lists {

    /**
     * @param list A list
     * @param   The list element type
     * @return A randomly chosen element from the provided list, or null if the list is null or empty
     */
    public static  T getRandomFrom(List list) {
        return Iterables.isNullOrEmpty(list) ? null : list.get(ThreadLocalRandom.current().nextInt(list.size()));
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy