jeudi 1 janvier 2015

Use of If/Else Statement in Java considering memory IO

I know this might be stupid question, but i am wondering when is the right time to use if/else statement.


Let's say we are constructing a heap by giving maximum heap size in primitive java int type. And this is my constructor.



public Heap(int maximumSize) {
this.maximumSize = maximumSize;
if (maximumSize < 1) {
this.maximumSize = 100;
}
data = new int[this.maximumSize];
}


And i can write this also as



public Heap(int maximumSize) {
if (maximumSize < 1) {
this.maximumSize = 100;
} else {
this.maximumSize = maximumSize;
}
data = new int[this.maximumSize];
}


I am wondering which is more efficient way considering all low level processes?


Aucun commentaire:

Enregistrer un commentaire