Java ThreadLocalRandom getRandomIntegerElement(List list)

Here you can find the source of getRandomIntegerElement(List list)

Description

get Random Integer Element

License

Open Source License

Declaration

public static Integer getRandomIntegerElement(List<Integer> list) 

Method Source Code


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

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

public class Main {
    public static Integer getRandomIntegerElement(List<Integer> list) {
        Integer selectedElement = null;

        if (list != null && !list.isEmpty()) {
            int listSize = list.size();
            int randomIndex = ThreadLocalRandom.current().nextInt(0, listSize);
            selectedElement = list.get(randomIndex);
        }// www . j a va 2 s  .com

        return selectedElement;
    }
}

Related

  1. getRandomInt(int a, int b)
  2. getRandomInt(int limit)
  3. getRandomInt(int n)
  4. getRandomInt(int r)
  5. getRandomInteger()
  6. getRandomNumbers(Integer startNumber, Integer endNumber, Integer pageSize, Integer numNumbers)
  7. getRandomPassword()
  8. getRandomStr(int len)
  9. getRandomString(int length)