Skip to main content This browser is no longer supported. Show
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support. String.Equals Method
DefinitionDetermines whether two String objects have the same value. In this articleOverloads
Equals(String, StringComparison)Determines whether this string and a specified String object have the same value. A parameter specifies the culture, case, and sort rules used in the comparison.
Parametersvalue String The string to compare to this instance. comparisonType StringComparison One of the enumeration values that specifies how the strings will be compared. ReturnsBoolean
ExceptionsExamplesThe following example creates a string array that consists of an uppercase "I", a lowercase "i", and a dotless "ı". It then calls the Equals(String, StringComparison) method to compare them by using each possible StringComparison enumeration value.
RemarksThe
See also
Applies toEquals(String, String)Determines whether two specified String objects have the same value.
Parametersa String The first string to compare, or b String The second string to compare, or ReturnsBoolean
ExamplesThe following example demonstrates the Equals method.
RemarksThis method performs an ordinal (case-sensitive and culture-insensitive) comparison. See also
Applies toEquals(String, String, StringComparison)Determines whether two specified String objects have the same value. A parameter specifies the culture, case, and sort rules used in the comparison.
Parametersa String The first string to compare, or b String The second string to compare, or comparisonType StringComparison One of the enumeration values that specifies the rules for the comparison. ReturnsBoolean
ExceptionsExamplesThe following example compares three sets of strings by using each member of the StringComparison enumeration. The comparisons use the conventions of the English (United States), Thai (Thailand) and Turkish (Turkey) cultures. Note that the strings "a" and "a-" are considered equivalent in the "th-TH" culture but not in the others, while "i" and "İ" are considered equivalent in the "tr-TR" culture when case is ignored but not in the other cultures.
RemarksThe See also
Applies toEquals(Object)Determines whether this instance and a specified object, which must also be a String object, have the same value.
Parametersobj Object The string to compare to this instance. ReturnsBoolean
ExamplesThe following example demonstrates the Equals method.
RemarksThis method performs an ordinal (case-sensitive and culture-insensitive) comparison. See also
Applies toEquals(String)Determines whether this instance and another specified String object have the same value.
Parametersvalue String The string to compare to this instance. ReturnsBoolean
ImplementsExamplesThe following example demonstrates the Equals method. It compares the title-cased word "File" with an equivalent word, its
lowercase equivalent, its uppercase equivalent, and a word that contains LATIN SMALL LETTER DOTLESS I (U+0131) instead of LATIN SMALL LETTER I (U+0069). Because the Equals(String) method performs an ordinal comparison, only the comparison with an identical word returns
RemarksThis method performs an ordinal (case-sensitive and culture-insensitive) comparison. See also
Applies toWhich of these method of class string is used to compare two string objects for their equality Isequal () equals () equals () Isequals ()?Java String equals() Method
The equals() method compares two strings, and returns true if the strings are equal, and false if not.
Which of these method of a class string is used to compare two string?Using String. equals() :In Java, string equals() method compares the two given strings based on the data/content of the string. If all the contents of both the strings are same then it returns true.
Which method can be used to compare two strings for equality?1) equals() and equalsIgnoreCase()
The equals() method is used to compare the equality of both the strings. This comparison is case sensitive, but if we want to compare two strings irrespective of their case differences, then we use the equalsIgnoreCase() method.
What is the value returned by function compareTo () If the invoking string is less than the string compared zero value less than zero value greater than zero one?Explanation: compareTo() function returns zero when both the strings are equal, it returns a value less than zero if the invoking string is less than the other string being compared and value greater than zero when invoking string is greater than the string compared To 4. 10.
|