1

Does the Java foreach loop create a new object?

view story
linux-howto

http://stackoverflow.com – Will Java create a new object each time a foreach loop is entered? I'm not talking about each iteration, but if you have a foreach loop that is used multiple times, is it creating objects each time? Simple Example: for(Object o : Objects) { for(Object p : Objects2) { } } Would there only be one p per execution, or would p be instantiated for each Object o? Does the Garbage Collector have to recover an object from the foreach loop each time it is exited? More specifically, I'm writing some Android based game code. It will iterate over all the game objects at a given rate per s (HowTos)