Forums Register Login

What happens?

+Pie Number of slices to send: Send
Is there any difference in this code? If there is an SomeObject array called array...
SomeObject object = null;
for (int i = 0; i < array.length; i++) {
object = array[i];
...some processing...
}
or........
for (int i = 0; i < array.length; i++) {
SomeObject object = array[i];
...some processing...
}
+Pie Number of slices to send: Send
 

Originally posted by Aaron Webb:
Is there any difference in this code? If there is an SomeObject array called array...
SomeObject object = null;
for (int i = 0; i < array.length; i++) {
object = array[i];
...some processing...
}
or........
for (int i = 0; i < array.length; i++) {
SomeObject object = array[i];
...some processing...
}


I think no. 2 is wrong, you have to declare before the loop.
+Pie Number of slices to send: Send
Either form is acceptable. The second form creates a bunch of unneeded pointers but since they are on the stack and not the heap, it isn't a big deal.
+Pie Number of slices to send: Send
both are correct and work fine i just didn't know if there was a performance difference one way or the other
+Pie Number of slices to send: Send
cool thats what i was wondering...thanks
+Pie Number of slices to send: Send
 

Originally posted by Aaron Webb:
both are correct and work fine i just didn't know if there was a performance difference one way or the other


Well, did you try to benchmark the two? That would give you the only authentic answer...
+Pie Number of slices to send: Send
How do you benchMark?
Is it Just a way of checking how much time each loop takes.Do you do it using time functions.?
Or is there someother method to do this?
Thanks.
You learn how to close your eyes and tell yourself "this just isn't really happening to me." Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1096 times.
Similar Threads
Check an array for equality
array sort
Casting
The return statement question
Vector and ArrayList Behavior got me in a loop...
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 19, 2024 00:52:21.