Logo 
Search:

Java Articles

Submit Article
Home » Articles » Java » Homework HelpRSS Feeds

Program to show the comparing of Strings for equality

Posted By: Zivah Levi     Category: Java     Views: 2939

A Java Program to show the comparing of Strings for equality.

Code for Program to show the comparing of Strings for equality in Java

publicclass JAVA_046
 {

    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.equals(String3))
          System.out.println("String1.equals(String3) is True, so Strings are equal");

       else
          System.out.println("String1.equals(String3) is False, so Strings are not equal");

       String3="TOO many cooks";

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

       if(String1.equals(String3))
          System.out.println("String1.equals(String3) is True, so Strings are equal");

       else
          System.out.println("String1.equals(String3) is False, so Strings are not equal");

       if(String1.equalsIgnoreCase(String3))
          System.out.println("String1.equalsIgnoreCase(String3) is True, " +
                                                       "so Strings are equal ignoring case");

       else
          System.out.println("String1.equalsIgnoreCase(String3) is False, " + 
                                                                 "so Strings are different");
    }
 }
  
Share: 


Didn't find what you were looking for? Find more on Program to show the comparing of Strings for equality Or get search suggestion and latest updates.

Zivah Levi
Zivah Levi author of Program to show the comparing of Strings for equality is from Eilat, Israel.
 
View All Articles

Related Articles and Code:


 
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!