Is there a way to initialise an array of integers (or possibly any array) to a constant value other than zero (or null) which are the defaults, without a for loop?
Ideally I am looking for a function like “ones” in matlab, which is not only neater but also more efficient.
Arrays.fill()is the method you’re after. (Although internally it still uses a for loop, so unlikeSystem.arrayCopy(), it isn’t any faster.)P.s.:
Arrays, and its collection-based counterpartCollectionsare two extremely useful classes in general.