I would suggest using if-else block (the first approach) because it increases the readability. However for considering performance i had sampled your two approaches in a program. The code is as follows.
public class test {
public static void main(String args[])
{
int count1=0,count2=0;
for(int i=0;i<50000;i++)
{
long timeStart=System.nanoTime();
method1(false);
long timeEnd=System.nanoTime();
long result1=timeEnd-timeStart;
System.out.println("\n\nTime taken for method 1 is :"+result1);
long Start=System.nanoTime();
method2(false);
long End=System.nanoTime();
long result2=End-Start;
System.out.println("Time taken for method 2 is :"+result2);
if(result1>result2)
{
//increment count2 when result2's execution speed is high (i.e) less time
count2++;
}
if(result1<result2)
{
//increment count1 when result1's execution speed is high
count1++;
}
}
System.out.println("\n\ncount1 value at the end is\t"+count1);
System.out.println("count2 value at the end is\t"+count2);
}
public static int method1(boolean condition)
{
int valueA = 3;
int valueB = 5;
if (condition == true) {
return valueA;
}
else
{
return valueB;
}
}
public static int method2(boolean condition)
{
int valueA = 3;
int valueB = 5;
if (condition == true) {
return valueA;
}
return valueB;
}
}
Output:
Testcase 1:
count1 value at the end is 10707
count2 value at the end is 10977
Testcase 2:
count1 value at the end is 10310
count2 value at the end is 10225
Testcase 3:
count1 value at the end is 9590
count2 value at the end is 10445
Testcase 4:
count1 value at the end is 10687
count2 value at the end is 10435
Testcase 5:
count1 value at the end is 10670
count2 value at the end is 10223
Testcase 6:
count1 value at the end is 10594
count2 value at the end is 10810
Overall cumulative result of all 6 test cases is count1 =62558 count2=63115
so there is no much difference in terms of performance on both approaches. So better thing is to use if else block as it gives equal performance (in terms of time) and increases readability.