Consider this code snippet
import java.util.Date;
class Test {
public static void main(String[] args) {
Date date = null;
long startTime = System.currentTimeMillis();
if(date == null) {
System.out.println("null == date");
}else {
System.out.println("date found "+date);
}
long stopTime = System.currentTimeMillis();
long elapsedTime = stopTime - startTime;
System.out.println(elapsedTime);
}
}
In if condition I used date==null I wanted to know is there there any reduction in time complexity or vice versa if I choose to write null==date
PS- for both the condition my code is producing output as 0 but what if the code is complex and has heavy operations ?
Aucun commentaire:
Enregistrer un commentaire