Simple question, what is the fastest way to iterate through
collections on Android? I generally use collection.iterator(); and the
iterator.next() to iterate through the whole collection. Is it any
faster to drop that and iterate with "old" (and I use the term old
loosely...) :

for( int i=0; i<collection.size(); i++) ?

I was thinking of getting the collection.size() into a separate
variable so I wouldn't be asking the collection it's size all the time
so basically the for loop would turn into something like this:

int size = collection.size();
for( int i=0; i<size; i++ )
   collection.get(i);

Any better? Speed wise, I mean. I'm in a point where I need to get
every possible inch of speed for my application.
Or maybe allocate everything into Lists in the start, and once I know
the correct amount of data, I turn all that into arrays and drop the
Lists so I can have array[index] (Log(1) access, right? OH wait.. how
did this go again >_< ) access instead of having the "slow" method
calls in between like .get(); when accessing the data in the
collection.

And what about getters & setters for Classes? Like let's have a
Vector2D class that contains obvious integer x and integer y values.
What is the fastest way to access them inside the class? Have them as
public and just straight Vector2D.x = someValue; or through getters
and setters? I've had much debate with my tutor about this (working on
my final year project) but not to get too much into details of it...

Also all links for further Android application optimisation are more
than welcome and greatly appreciated (I read the googles docs on this
already). Plus if you have found some really good tricks / quirks on
Android to punish the device even more so it runs faster, do share, do
share. Heh.

Please be gentle on me, I'm such a beginner in all things Android that
I feel absolutely dumb as a boot for asking these kind of things. I
come from strong C++ / Java background but getting the extra inch of
speed for everything on Android is so different than optimizing code
for PC side and not that you even have to do it on PC side that often.

Fire away gents and ladies!

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to