Java implementation of the equals method
KW.java
class KW
{
    public static void main(String args[])
    {
        String s1="HELLO WORLD";
        String s2=s1;
        String s3="Hello World";

        boolean b;
        b=s1.equals(s2);
        System.out.println(b);

        b=s2.equals(s3);
        System.out.println(b);

        b=s1.equalsIgnoreCase(s3);
        System.out.println(b);
    }
}
Output
kodingwindow@kw:~$ javac KW.java
kodingwindow@kw:~$ java KW true false true kodingwindow@kw:~$
Advertisement