The first example is fine. There isn't any memory allocation going on there, other than a stack variable allocation and deallocation each time through the loop (very cheap and quick).
The reason is that all that is being 'allocated' is a reference, which is a 4 byte stack variable (on most 32 bit systems anyway). A stack variable is 'allocated' by adding to a memory address representing the top of the stack, and so is very quick and cheap.
What you need to be careful of is for loops like:
for (int i = 0; i < some_large_num; i++)
{
String something = new String();
//do stuff with something
}
as that is actually doing memory allocatiton.