In Java, is there a one-line way to create a collection that is initialized with n clones of an object?
I'd like the equivalent of this:
foo = vector<vector<int> >(10);
c++, creates 10 different empty vectors[ [] for i in range(10) ]
Python, an array of 10 distinct empty arraysArray.new(10) { [] }
Ruby, same as Python
In Java, I've only found
new ArrayList<ArrayList<Integer> >(Collections.nCopies(10, new ArrayList<Integer>()))
However, this is not equivalent to the other examples, because the lists alias.
Is there a way to create an array of distinct object clones, without using a for loop, and preferably without resorting to external libraries?