Free Data Structures and Algorithms Course









Subscribe below and get all best seller courses for free !!!










OR



Subscribe for all free courses

How to compare Strings in Java with or without case sensitivity ?

Program to compare Strings in Java with or without case sensitivity

package com.hubberspot.example;

public class StringComparison {
 
   public static void main(String[] args) {
  
 String first = "StringComparison";
 String second = "StringComparison";
 String third = "stringcomparison";
 String fourth = "TesTcoMpaRisOn";
 String fifth = "STRINGCOMPARISON";
  
 System.out.println("first.equals(second) : "+first.equals(second));
 System.out.println("first.equals(third) : "+first.equals(third));
 System.out.println("first.equals(fourth) : "+first.equals(fourth));
 System.out.println("first.equals(fifth) : "+first.equals(fifth));
 System.out.println();
 System.out.println("first.equalsIgnoreCase(second) : "
                    +first.equalsIgnoreCase(second));
 System.out.println("first.equalsIgnoreCase(third) : "
                    +first.equalsIgnoreCase(third));
 System.out.println("first.equalsIgnoreCase(fourth) : "
                    +first.equalsIgnoreCase(fourth));
 System.out.println("first.equalsIgnoreCase(fifth) : "
                    +first.equalsIgnoreCase(fifth));
 System.out.println();
  
 System.out.println("second.equals(third) : "+second.equals(third));
 System.out.println("second.equals(fourth) : "+second.equals(fourth));
 System.out.println("second.equals(fifth) :    "+second.equals(fifth));  
 System.out.println();
 System.out.println("second.equalsIgnoreCase(third) : "
                    +second.equalsIgnoreCase(third));
 System.out.println("second.equalsIgnoreCase(fourth) : "
                    +second.equalsIgnoreCase(fourth));
 System.out.println("second.equalsIgnoreCase(fifth) : "
                    +second.equalsIgnoreCase(fifth));  
 System.out.println();
  
 System.out.println("third.equals(fourth) : "+third.equals(fourth));
 System.out.println("third.equals(fifth) : "+third.equals(fifth));
 
 System.out.println("third.equalsIgnoreCase(fourth) : "
                     +third.equalsIgnoreCase(fourth));
 System.out.println("third.equalsIgnoreCase(fifth) : "
                     +third.equalsIgnoreCase(fifth));
  
 System.out.println();
 System.out.println("fourth.equals(fifth) : "+fourth.equals(fifth));
 System.out.println();
 System.out.println("fourth.equalsIgnoreCase(fifth) : "
                     +fourth.equalsIgnoreCase(fifth));
 System.out.println();
   }

}




Output of the program :




 
© 2021 Learn Java by Examples Template by Hubberspot