The return type of this function is an integer. Strings will be considered as not equal even after the equal, but the case is not in a similar order. This will also check for the strings are in the same case. If both strings will be equal, then this function will return the 0. Int compare = pareToIgnoreCase(str2) Syntax int compareTo(String str) Let’s see the same strings as mentioned above using this function compareToIgnoreCase(). Java compareToIgnoreCase() function – In case we want the string to be compared with the case matching then this function will be helpful for us. In other words, the strings are not equal for str1 and str2. But in the above case we will not get the 0. We will not 0 in compare identifier if both strings are equal. In the below code we have the same string ‘Hello World’ but in the str2 we have ‘Hello’ word with small ‘h’. If we would like to compare the same text or the string with the case checking, this function is best to do so. Java compareTo() function – This is a case sensitive function for string comparison. String str1 = "Hello World" īoolean equalsStr = str1.equalsIgnoreCase(str2) This ignore the case checking in addition to the equals() function workings. String str1 = "Hello World" ĮqualsIgnoreCase() function – This function working is very similar to the compareToIgnoreCase() function. The return type of this function is Boolean. This works the way compareTo() works for strings. ("Both strings are equal.") Īfter running the above code, we can see both strings are equals.Įquals() function – Again, this function is a case-sensitive for checking whether two strings are equals or not.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |