consider the following code segment

    String a="hello";
    String b= "hello";
    if (a==b) 
    System.out.println("they are equal");

i ) Why does it not generate output?
ii)How can we rewrite the program such that it will print the output?
jwenting commented: duplicate -3

Did you execute that code?
I thought not.
Try running it - it does generate the output they are equal
It looks like you are asking the wrong question.