java – What is the best way to define variables to use in a for loop?

I have a for loop where I browse a map and create another map. What is the best way to define variables in this case?

There are two ways to do that:

  1. Define the variables outside the for loop and assign values ​​to them in the for loop:

    public map getMyMap (TypeA[] my table)
    Map myMap = new HashMap <> ();
    K myKey;
    V myValue;
    TypeA typeA;
    
    for (int i = 0; i <myArray.length; i ++) {
    typeA = myArray[i];
    myKey = typeA.getNumber ();
    myValue = typeA.getString ();
    myMap.put (myKey, myValue);
    }
    return myMap;
    }
    
  2. Define the variables in the for loop and use them here.

    public map getMyMap (TypeA[] my table)
    Map myMap = new HashMap <> ();
    TypeA typeA;
    
    for (int i = 0; i <myArray.length; i ++) {
    typeA = myArray[i];
    K myKey = typeA.getNumber ();
    V myValue = typeA.getString ();
    myMap.put (myKey, myValue);
    }
    return myMap;
    }
    

From a performance point of view, what should be the best way?