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
  • 3,064
  • 8
  • 36
  • 65
  • 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
  • 62,134
  • 8
  • 100
  • 147