1

I need to fill an ArrayList with some (random) data. I wonder if Java 8/9 allows a more concise way than this:

List list = new ArrayList();
for (int ii=0;ii<100;ii++)
list.add(UUID.randomUUID().toString());

Thanks!

Carla
  • 2,566
  • 3
  • 26
  • 51
  • Is this what you're looking for ? http://stackoverflow.com/questions/33140535/java-8-fill-arraylist – DamCx Feb 16 '17 at 09:25

1 Answers1

6

Probably this will do:

Supplier<String> supplier = () -> UUID.randomUUID().toString();
List<String> list = Stream.generate(supplier).limit(100).collect(Collectors.toList()); 
Konstantin Yovkov
  • 60,548
  • 8
  • 97
  • 143