Check if two strings are same ignoring their cases | Function to compare two Strings ignoring their cases ; Convert to lowercase using toUpperCase function ; Comparing both using inbuilt function ; if Strings are equal , return true otherwise false ; Function to print the same or not same if Strings are equal or not equal ; Driver Code
class GFG { static boolean equalIgnoreCase ( String str1 , String str2 ) { int i = 0 ; str1 = str1 . toUpperCase ( ) ; str2 = str2 . toUpperCase ( ) ; int x = str1 . compareTo ( str2 ) ; if ( x != 0 ) { return false ; } else { return true ; } } static void equalIgnoreCaseUtil ( String str1 , String str2 ) { boolean res = equalIgnoreCase ( str1 , str2 ) ; if ( res == true ) { System . out . println ( " Same " ) ; } else { System . out . println ( " Not ▁ Same " ) ; } } public static void main ( String [ ] args ) { String str1 , str2 ; str1 = " Geeks " ; str2 = " geeks " ; equalIgnoreCaseUtil ( str1 , str2 ) ; str1 = " Geek " ; str2 = " geeksforgeeks " ; equalIgnoreCaseUtil ( str1 , str2 ) ; } }