lundi 29 juin 2015

Saving a generated stream into an ArrayList

What I'm supposed to do is create an ArrayList of random numbers via stream.generate. Code below is my attempt of trying to save it into an ArrayList, but it's of type "object". I figured I have to somehow map it into int first, but I don't know how. Code right now doesnt work.

public ArrayList<Integer> createRandomList(ArrayList<Integer> list, int amount) {
     ArrayList<Integer> a = Arrays.asList(Stream.generate(new Supplier<Integer>() {
                    @Override
                    public Integer get() {
                        Random rnd = new Random();
                        return rnd.nextInt(100000);
                    }
                }).limit(amount).mapToInt.toArray());
}




Aucun commentaire:

Enregistrer un commentaire