Java array efficiency

I am not 100% sure that the mechanism is in action, so I decided to publish it here for further clarification

I'm working on a project that should handle a lot of data in Java (it must be Java) I want it to be as efficient as possible Efficiency I mean that memory and speed computing should come first, and readability should come second

Now I have two ways to store my data: create a MyObject array

1) MyObject[][] V = new MyObject[m][n]

Or create two int arrays:

2) int[][] V = new int[m][n]

3) int[][] P = new int[m][n]

Obviously, MyObject contains at least two fields and some methods Now I notice that when looping through the MyObject array to allocate values, I must call new, otherwise I will get a null pointer exception This means that the new content in line 1 is not enough This is a more expensive operation than parameters, P [i] [J] = n, considering that arrays are also objects in Java?

Solution

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
分享
二维码
< <上一篇
下一篇>>