Logo 
Search:

Java Articles

Submit Article
Home » Articles » Java » Homework HelpRSS Feeds

Program to show the use of Comparison operator (==) for comparing Strings

Posted By: Ramon Davis     Category: Java     Views: 14893

A Java Program to show the use of Comparison operator (==) for comparing Strings.

Code for Program to show the use of Comparison operator (==) for comparing Strings in Java

publicclass JAVA_045
 {

    publicstaticvoid main(String[] args)
    {
       String String1="Too many ";
       String String2="cooks";
       String String3="Too many cooks";

       String1+=String2;

       System.out.println("Test # 1");
       System.out.println("String3 is now : " + String3);
       System.out.println("String1 is now : " + String1);

       if(String1==String3)
          System.out.println("String1==String3 is True, " +
                             "String1 and String3 point to the same String");

       else
          System.out.println("String1==String3 is False, " +
                             "String1 and String3 do not point to the same String");

       String3=String1;

       System.out.println("\n\nTest # 2");
       System.out.println("String3 is now : " + String3);
       System.out.println("String1 is now : " + String1);

       if(String1==String3)
          System.out.println("String1==String3 is True, " +
                             "String1 and String3 point to the same String");

       else
          System.out.println("String1==String3 is False, " +
                             "String1 and String3 do not point to the same String");
    }
 }
  
Share: 



Ramon Davis
Ramon Davis author of Program to show the use of Comparison operator (==) for comparing Strings is from Houston, United States.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!