I am creating a list of x,y values for tracking positions. Working on android optimization is very important, so I am wondering which method would be better from a resource usage standpoint.
Method 1:
Create a class(Position) containing an int for x and y, then create a list: positions.
Method 2:
Create parallel lists: positionsX and positionsY.
I am asking because method 1 seems to be the most user friendly for OO coding, but I don’t know enough about the inner workings of Java or android and I’m afraid the overhead of the extra class would cancel out any benefits.
Or are they close enough that it doesn’t really matter?
The performance difference between the two solutions is negligible. Depending on more detailed specifics such as what type of lists (arrays, lists, maps, etc.) and how you are accessing the data will determine which one is negligibly faster.
However, from a readability, OO, and maintainability standpoint, Method 1 wins by a landslide.