Java – how to avoid initialization of large arrays
•
Java
I assigned a lot of doubles
double[] x = new double[ n ];
Where n is large, I want to avoid initialization to save time Is it possible?
Solution
Short answer: No, arrays are always cleared when they are created
If your analysis shows that this is a major bottleneck, you can consider retaining an array instance pool, and the length of each collection is greater than N. the problem is that you may need a wrapper object to contain the data array and the actual length used, because you can no longer use data length.
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码