Hi,
I am not able to understand the precedence of ternary operator while doing
string concatenation
Source :Self
public class StringTest {
public static void main(String[] args)
{
final String s1 = "Foo";
final String s2 = "Bar";
final boolean b = true;
String s3 = b?s1:s1 + s2;
System.out.println("s3 is when no brackets around ternary operator " + s3); //s3 = "Foo" // 1
String s4 = (b?s1:s1) + s2;
System.out.println("s4 is when brackets around ternary operator " + s4); //s4 = "FooBar" //2
}
}
Can anyone please explain me at //1 and //2 places?
It may be silly one , but i am not able to figure it out.
please help me