Which of the below three ways of declaring variables to be used within a loop is better (faster/less memory used/maintainability)?
Would the choice change if the method had other processing and other for loops needing the same variables?
CASE 1:
public static void setMaxDate(Log[] logs, Date maxDate) {
for (int i = 0, iLen = logs.length; i < iLen; i++) {
Log log = (Log) logs[i];
Date date = log.getDate();
if (date == null || date.compareTo(maxDate) > 0) {
log.setDate(maxDate);
} // end if
} // end for
}
CASE 2:
public static void setMaxDate(Log[] logs, Date maxDate) {
Date date = null;
Log log = null;
for (int i = 0, iLen = logs.length; i < iLen; i++) {
log = (Log) logs[i];
date = log.getDate();
if (date == null || date.compareTo(maxDate) > 0) {
log.setDate(maxDate);
} // end if
} // end for
}
CASE 3:
public static void setMaxDate(Log[] logs, Date maxDate) {
for (int i = 0, iLen = logs.length; i < iLen; i++) {
final Log log = (Log) logs[i];
final Date date = log.getDate();
if (date == null || date.compareTo(maxDate) > 0) {
log.setDate(maxDate);
} // end if
} // end for
}