i wonder about performance of using method call as foreach argument for getting collection. Lets look at example:
for (Entry<K, V> entry : map.entrySet()) {
doing.stuff();
}
I suppose that JVM will call map.entrySet() only once before starting loop, take first element, take his iterator and iterate over it, calling map.entrySet() never again, or in case of arrays just iterating over it with locally created int iterator (or sth like that), but I dont know how JVM works, so I'd like to be sure - does it work this way, or is better to save collection before loop and pass it as local var, instead of calling an getter inside loop ?