
What is the output and why of below :
String s1 = "Hello"; if(s1.replace('H','H')== "Hello") System.out.println("yes"); else System.out.println("No"); if(s1.replace("H", "H")== "Hello") System.out.println("yes"); else System.out.println("No");

A string cannot be compared with == operator. It is always compared with equals() function.
Compare string:
class Replace
{
public static void main(String[] args)
{
String s1 = "Hello";
if(s1.replace('H','H').equals( "Hello")){
System.out.println("yes");
}
else {
System.out.println("No");
}
if(s1.replace("H", "H").equals("Hello")){
System.out.println("yes");
}
else{
System.out.println("No");
}
}
}

Thanks for the prompt reply. But, I understand the correct function for comparison is ".equals()" and not "==" . I wish to understand what is the difference when we use function replace(char old, car new) and replace ("stringOld", "stringNew") which causes the above below stated output(obtained after running the code)?
yes No