Write a program in java to demonstrate equals() method and == operators?

class Strings

{

                public static void main(String args[])

                {

                                String s1="Vikrant";

                                String s2="Vikrant";

                                String s3=new String("Vikrant");

                                String s4="vikrant";

                                System.out.println(s1.equals(s2));

                                System.out.println(s1==s2);

                                System.out.println(s1.equals(s3));

                                System.out.println(s1==s3);

                                System.out.println(s1.equals(s4));

                                System.out.println(s1==s4);

                                System.out.println(s1.equalsIgnoreCase(s4));

                }

}

equals() method and ==.PNG

, , , , , , ,

Leave a Reply