Re: Quick way to initialize array with all zeros
- From: "Andrew Thompson" <andrewthommo@xxxxxxxxx>
- Date: 31 Mar 2007 08:21:15 -0700
On Apr 1, 12:28 am, "Andrew Thompson" <andrewtho...@xxxxxxxxx> wrote:
On Mar 31, 11:59 pm, Patricia Shanahan <p...@xxxxxxx> wrote:
001 wrote:
I want to initialize a large array with 0's... do I have to use a for-loop
or is there some trick to accomplish this?
new int[n] is an all zero int array of size n. If you have an existing
array and need to reinitialize it to zero, use Arrays.fill.
I 'object' to such simplistic answers to what is
effectively a complex question. My first question
for the OP would be, what do you mean by 'quick'?
There are two potential meanings, AFAIU.
1) quick to code.
2) quick to run.
D'oh! In my (mild) irritation I forgot to
mention two important things.
1) Premature optimization
These types of questions smack of premature
optimization. Code for clarity and let the
JIT do its job until such times as a *profiler*
indicates a bottleneck based on the array
initialisation.
2) (Stressing) code clarity
The Array.fill() method would be preferable
for code clarity. Why code three lines, for
something that can be expressed in one?
Andrew T.
.
- References:
- Quick way to initialize array with all zeros
- From: 001
- Re: Quick way to initialize array with all zeros
- From: Patricia Shanahan
- Re: Quick way to initialize array with all zeros
- From: Andrew Thompson
- Quick way to initialize array with all zeros
- Prev by Date: Re: Desktop Java app: 3D photo-sharing
- Next by Date: Re: collection of a class
- Previous by thread: Re: Quick way to initialize array with all zeros
- Next by thread: Re: Quick way to initialize array with all zeros
- Index(es):
Relevant Pages
|