0

I have this Java class called MyObject and I want to instantiate a ArrayList/array of 50 non-null MyObject elements in one line.

So in Python that would be something like:

_list = [MyObject() for i in range(50)]

Any ideas are greatly appreciated.

E. Kaufman
  • 129
  • 2
  • 11

1 Answers1

0

A solution for plain arrays could look like this (not a one liner though):

MyObject[] arr = new MyObject[50];
Arrays.setAll(arr, index -> new MyObject());
noIdeaAtAll
  • 183
  • 1
  • 7