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

Recommended Answers

All 2 Replies

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.