Array index search versus Instance field search

Is someArray [index] a faster way to get the value than someObject.field?

eg:.

if (intArray [i] == 42) {// do stuff}

VS

if (someObject.x == 42) {// do stuff}

I will try to check it out soon and publish the results; just wondering if you had all the thoughts.

+3
source share
1 answer

I would expect that using an array element would be much faster, since the link points directly to the return value.

When you refer to an element in the Object field, the runtime should determine which class the member belongs to, etc., and the process will take longer.

+2

Source: https://habr.com/ru/post/1733745/


All Articles