populate Double List with random double value - Java java.util

Java examples for java.util:List Element

Description

populate Double List with random double value

Demo Code


//package com.java2s;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static void main(String[] argv) {
        int numberOfItems = 42;
        System.out.println(populateDoubleList(numberOfItems));
    }//w w  w .  ja  va2s .c  o  m

    public static List<Double> populateDoubleList(int numberOfItems) {
        List<Double> dummyDoubleList = null;
        if (numberOfItems > 0) {
            dummyDoubleList = new ArrayList<Double>();
            for (int i = 0; i < numberOfItems; i++) {
                final double randomNumber = (Math.random() * numberOfItems);
                dummyDoubleList.add(randomNumber);
            }
        }
        return dummyDoubleList;
    }
}

Related Tutorials