Java gem of the day: nCopies() ('x' in Java)

jdavidb on 2008-04-09T20:57:18

In Perl:

@p = ('?') x 15;

In Java:

List p = Collections.nCopies(15, '?');


Nitpicking...

Mr. Muskrat on 2008-04-09T21:30:56

To be equivalent code, shouldn't that second one be this?

List<String> p = Collections.nCopies(15, '?');

Re:Nitpicking...

jdavidb on 2008-04-10T13:24:58

That's not nitpicking! That's helpfully correcting my typo! Thank you!!

Re:Nitpicking...

jdavidb on 2008-04-10T13:26:19

Actually to be "equivalent" I should probably also declare @p with my. :)